func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 300500;   int n, m, q;   vector<int> g[maxn];   bool used[maxn];   int p[maxn], sz[maxn], diameter[maxn];   int maxi, maxiV;   void dfs(int v, int depth, int p) {     if (depth > maxi) {       maxi = depth;       maxiV = v;     }     for (size_t i = 0; i < g[v].size(); i++) {       int to = g[v][i];       if (to != p) dfs(to, depth + 1, v);     }   }   int findLongestWay(int v) {     maxi = -1;     dfs(v, 0, -1);     maxi = -1;     dfs(maxiV, 0, -1);     return maxi;   }   void init() {     for (int i = 1; i <= n; i++) p[i] = i, sz[i] = 1, diameter[i] = 0;   }   int getSet(int v) {     if (p[v] == v) return v;     return p[v] = getSet(p[v]);   }   void unionSets1(int x, int y) {     x = getSet(x);     y = getSet(y);     if (sz[x] > sz[y]) swap(x, y);     sz[y] += sz[x];     p[x] = y;   }   int rad(int x) { return (diameter[x] + 1) / 2; }   void unionSets2(int x, int y) {     x = getSet(x);     y = getSet(y);     if (x == y) return;     if (sz[x] > sz[y]) swap(x, y);     sz[y] += sz[x];     p[x] = y;     diameter[y] = max(rad(x) + rad(y) + 1, max(diameter[x], diameter[y]));   }   int query(int x) { return diameter[getSet(x)]; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     ;     cin >> n >> m >> q;     init();     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);       unionSets1(x, y);     }     for (int i = 1; i <= n; i++) {       int pp = getSet(i);       if (!used[pp]) {         used[pp] = 1;         diameter[pp] = findLongestWay(i);       }     }     while (q--) {       int t, x, y;       cin >> t;       if (t == 2) {         cin >> x >> y;         unionSets2(x, y);       } else {         cin >> x;         printf( %d n , query(x));       }     }   }   