超
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 300005;
int fa[maxn], len[maxn];
int find(int x) {
return x == fa[x]? x : fa[x] = find(fa[x]);
}
void un(int x, int y) {
int fx = find(x), fy = find(y);
if (fx != fy) {
fa[fx] = fy;
len[fy] = max(max(len[fx], len[fy]),(len[fx]+1)/2 + (len[fy]+1)/2 + 1);
}
}
vector <int> g[maxn]
int l, u;
void findfur(int x, int fa, int s) {
if (s >= l) l = s, u = x;
for (int i = 0; i < g[x].size(); i++) {
int y = g[x][i];
if (y ^ fa) findfur(y, x, s+1);
}
}
int gd(int st) {
l = 0; findfur(st, 0, 0);
l = 0; findfur(u, 0, 0);
return l;
}
signed main() {
cin.tie(0); ios::sync_with_stdio(0);
int n, m, q;
cin >> n >> m >> q;
for (int i = 1; i <= n; i++) {
fa[i] = i;
// len[i] = 1;
}
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
g[x].push_back(y); g[y].push_back(x);
fa[find(x)] = find(y);
}
for (int i = 1; i <= n; i++) if (i == fa[i]) len[i] = gd(i);
while (q--) {
int opt, x, y;
cin >> opt;
if (opt == 1) {
cin >> x;
cout << len[find(x)] << "\n";
} else {
cin >> x >> y;
un(x, y);
//cout << len[find(x)] << "\n";
}
}
}
显然,错误在于vector那一行(22行)没加分号。
然鹅

emm……一开始我觉得可能是Dev的BUG。
然鹅你谷IDE的编译出来也是这样。
有无大佬解释。