求锐评码风
  • 板块灌水区
  • 楼主yhylivedream
  • 当前回复13
  • 已保存回复13
  • 发布时间2024/4/13 13:23
  • 上次更新2024/4/13 15:11:36
查看原帖
求锐评码风
778022
yhylivedream楼主2024/4/13 13:23

RT,很多人吐槽我的码风,求各位大佬的意见。

problem

#include <bits/stdc++.h>

using namespace std;

const int kMaxN = 2e5 + 1;

struct V {
  int d, f;
  vector<int> e;
} v[kMaxN];

int n, x, y, a, b, c, p;

void S(int f, int x) {
  v[x].f = f;
  (v[x].d = v[f].d + 1) > v[y].d && (y = x);
  for (int i : v[x].e) {
    if (i != f) {
      S(x, i);
    }
  }
}

int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> x >> y;
    v[x].e.push_back(y), v[y].e.push_back(x);
  }
  S(0, y = 1), S(0, c = a = y);
  for (int i = b = y; i; i = v[i].f) {
    v[v[i].f].d = 1;
    for (int j : v[v[i].f].e) {
      if (j != v[v[i].f].f && j != i) {
        S(v[i].f, y = j);
        v[c].d < v[y].d && (c = y);
      }
    }
  }
  cout << v[b].d + v[c].d - 2 << '\n';
  cout << a << " " << b << " " << (c == a ? v[b].f : c);
  return 0;
}
2024/4/13 13:23
加载中...