func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int sub_tree[maxn], n, T[maxn], P[maxn][22], L[maxn], par[maxn], ans[maxn], nn;   set<int> adj[maxn];   void lca_dfs(int u, int p) {     T[u] = p;     L[u] = (p > -1) ? L[p] + 1 : 0;     for (int s : adj[u]) {       if (s == p) continue;       lca_dfs(s, u);     }   }   void sub_dfs(int u, int p) {     nn++;     sub_tree[u] = 1;     for (int nd : adj[u]) {       if (nd == p) continue;       sub_dfs(nd, u);       sub_tree[u] += sub_tree[nd];     }   }   int getCentroid(int u, int p) {     for (int nd : adj[u]) {       if (nd == p) continue;       if (sub_tree[nd] > nn / 2) return getCentroid(nd, u);     }     return u;   }   void decompose(int u, int p) {     nn = 0;     sub_dfs(u, -1);     int centroid = getCentroid(u, -1);     par[centroid] = p;     for (int nd : adj[centroid]) {       adj[nd].erase(centroid);       if (nd == p) continue;       decompose(nd, centroid);     }     adj[centroid].clear();   }   void init_LCA(int n) {     memset(P, -1, sizeof(P));     L[1] = 0;     lca_dfs(1, -1);     for (int i = 1; i <= n; i++) {       P[i][0] = T[i];     }     for (int j = 1; (1 << j) < n; j++) {       for (int i = 1; i <= n; i++) {         if (P[i][j - 1] != -1) P[i][j] = P[P[i][j - 1]][j - 1];       }     }   }   int lca_query(int p, int q) {     int tmp, log, i;     if (L[p] < L[q]) tmp = p, p = q, q = tmp;     log = 1;     while (1) {       int next = log + 1;       if ((1 << next) > L[p]) break;       log++;     }     for (i = log; i >= 0; i--)       if (L[p] - (1 << i) >= L[q]) p = P[p][i];     if (p == q) return p;     for (i = log; i >= 0; i--)       if (P[p][i] != -1 && P[p][i] != P[q][i]) p = P[p][i], q = P[q][i];     return T[p];   }   int getDist(int p, int q) {     int lca = lca_query(p, q);     return L[p] + L[q] - 2 * L[lca];   }   void update(int x) {     int u = x;     while (u != -1) {       ans[u] = min(ans[u], getDist(u, x));       u = par[u];     }   }   void query(int x) {     int mini = 1e8;     int u = x;     while (u != -1) {       mini = min(mini, ans[u] + getDist(u, x));       u = par[u];     }     printf( %d n , mini);   }   int main() {     int a, b, m;     scanf( %d %d , &n, &m);     ;     for (int i = 0; i < n - 1; i++) {       scanf( %d %d , &a, &b);       ;       adj[a].insert(b);       adj[b].insert(a);     }     init_LCA(n);     decompose(1, -1);     for (int i = 1; i <= n; i++) ans[i] = 1e8;     update(1);     for (int i = 0; i < m; i++) {       scanf( %d %d , &a, &b);       ;       if (a == 2)         query(b);       else         update(b);     }   }   