func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<int> adj[300005];   vector<int> vec;   int par[300005];   int vis1[300005];   int vis2[300005];   int vis3[300005];   int vis4[300005];   int dia[300005];   int root(int x) { return par[x] = ((par[x] == x) ? x : root(par[x])); }   void unite(int x, int y) { par[root(y)] = root(x); }   void dfs1(int x, int cnt, int &y, int &mx, int t) {     if (t)       vis1[x] = 1;     else       vis2[x] = 1;     int i;     for (i = 0; i < int(adj[x].size()); i++) {       if ((!vis1[adj[x][i]] && t) || (!vis2[adj[x][i]] && !t)) {         dfs1(adj[x][i], cnt + 1, y, mx, t);       }     }     if (cnt > mx) {       mx = cnt;       y = x;     }   }   bool dfs2(int x, int y) {     if (x == y) {       vec.push_back(y);       return true;     }     vis3[x] = 1;     int i;     for (i = 0; i < int(adj[x].size()); i++) {       if (!vis3[adj[x][i]]) {         if (dfs2(adj[x][i], y)) {           vec.push_back(adj[x][i]);           return true;         }       }     }     return false;   }   void dfs3(int x, int y) {     vis4[x] = 1;     unite(y, x);     int i;     for (i = 0; i < int(adj[x].size()); i++) {       if (!vis4[adj[x][i]]) {         dfs3(adj[x][i], y);       }     }   }   int main() {     int i, n, m, q, x, y, c;     scanf( %d %d %d , &n, &m, &q);     for (i = 0; i <= n; i++) par[i] = i;     for (i = 0; i < m; i++) {       scanf( %d %d , &x, &y);       adj[x].push_back(y);       adj[y].push_back(x);     }     int mx = 0;     for (i = 1; i <= n; i++) {       if (!vis1[i]) {         vec.clear();         mx = 0;         x = i;         y = i;         dfs1(i, 0, y, mx, 0);         mx = 0;         dfs1(y, 0, x, mx, 1);         dfs2(x, y);         int k = int(vec.size());         dfs3(x, vec[k / 2]);         dia[vec[k / 2]] = k - 1;       }     }     while (q--) {       scanf( %d %d , &c, &x);       if (c == 1) {         x = root(x);         printf( %d n , dia[x]);       } else {         scanf( %d , &y);         x = root(x);         y = root(y);         if (x == y) continue;         if (dia[x] >= dia[y]) {           unite(x, y);           dia[x] = max(dia[x], 1 + (dia[x] - dia[x] / 2) + (dia[y] - dia[y] / 2));         } else {           unite(y, x);           dia[y] = max(dia[y], 1 + (dia[x] - dia[x] / 2) + (dia[y] - dia[y] / 2));         }       }     }     return 0;   }   