func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, m, q;   vector<int> gr[300001];   int par[300001], comp[300001];   int mx[300001][2];   int dfs(int s, int k) {     comp[s] = k;     mx[s][0] = mx[s][1] = 0;     for (int i = 0; i < gr[s].size(); i++) {       if (comp[gr[s][i]] == -1) {         int p = dfs(gr[s][i], k) + 1;         par[gr[s][i]] = s;         if (p > mx[s][0]) {           mx[s][1] = mx[s][0];           mx[s][0] = p;         } else if (p > mx[s][1])           mx[s][1] = p;       }     }     return mx[s][0];   }   int mark[300001];   void dfs2(int s, int d) {     mark[s] = 1;     if (d > mx[s][0]) {       mx[s][1] = mx[s][0];       mx[s][0] = d;     } else if (d > mx[s][1])       mx[s][1] = d;     for (int i = 0; i < gr[s].size(); i++) {       if (!mark[gr[s][i]]) {         if (mx[s][0] == (mx[gr[s][i]][0] + 1)) {           ;           dfs2(gr[s][i], mx[s][1] + 1);         } else           dfs2(gr[s][i], mx[s][0] + 1);       }     }   }   int mlen[300001];   int mpar[300001];   int get(int id) {     if (par[id] == id) return id;     return par[id] = get(par[id]);   }   void merge(int x, int y) { par[x] = get(par[y]); }   int main() {     cin >> n >> m >> q;     int a, b;     for (int i = 0; i < m; i++) {       scanf( %d%d , &a, &b);       gr[a - 1].push_back(b - 1);       gr[b - 1].push_back(a - 1);     }     memset(comp, -1, sizeof comp);     int c = 0;     for (int i = 0; i < n; i++) {       if (comp[i] == -1) {         dfs(i, i);       }     }     memset(mark, 0, sizeof mark);     for (int i = 0; i < n; i++)       if (!mark[i]) dfs2(i, 0);     memset(mlen, -1, sizeof mlen);     for (int i = 0; i < n; i++) {       mlen[i] = mx[i][0] + mx[i][1];       mlen[comp[i]] = max(mlen[i], mlen[comp[i]]);       mpar[i] = mpar[comp[i]];       if (i == comp[i])         mpar[i] = i;       else if (mx[i][0] < mx[mpar[i]][0])         mpar[comp[i]] = i;     }     for (int i = 0; i < n; i++) {       mlen[i] = mlen[comp[i]];       mpar[i] = mpar[comp[i]];       par[i] = mpar[i];     }     for (int i = 0; i < q; i++) {       scanf( %d , &c);       if (c == 1) {         scanf( %d , &a);         printf( %d n , mlen[get(a - 1)]);       } else {         scanf( %d%d , &a, &b);         a = get(a - 1);         b = get(b - 1);         if (a != b) {           if (mx[a][0] >= mx[b][0]) {             merge(b, a);             mlen[a] = max(mlen[a], mx[a][0] + mx[b][0] + 1);             mx[a][0] = max(mx[a][0], mx[b][0] + 1);           } else {             merge(a, b);             mlen[b] = max(mlen[b], mx[b][0] + mx[a][0] + 1);           }         }       }     }     return 0;   }   