func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 10;   const int LOG = 18;   int n, m, par[MAX][LOG], h[MAX];   vector<int> graph[MAX];   int par_tree[MAX], mini[MAX];   void lca_dfs(int node, int p) {     if (p + 1) h[node] = h[p] + 1;     par[node][0] = p;     for (int k = 1; k < LOG; k++)       if (par[node][k - 1] + 1) par[node][k] = par[par[node][k - 1]][k - 1];     for (auto& target : (graph[node])) {       if (target != p) lca_dfs(target, node);     }   }   int get_lca(int a, int b) {     if (h[b] > h[a]) swap(a, b);     for (int k = LOG - 1; k >= 0; k--) {       if (par[a][k] + 1 && h[par[a][k]] >= h[b]) a = par[a][k];     }     if (a == b) return a;     for (int k = LOG - 1; k >= 0; k--)       if (par[a][k] != par[b][k]) {         a = par[a][k];         b = par[b][k];       }     return par[a][0];   }   int dist(int a, int b) { return h[a] + h[b] - 2 * h[get_lca(a, b)]; }   int processed[MAX], sizes[MAX];   int get_sizes(int node, int p) {     sizes[node] = 1;     for (auto& target : (graph[node])) {       if (!processed[target] && target != p)         sizes[node] += get_sizes(target, node);     }     return sizes[node];   }   int cent, cent_cost;   void select_cent(int node, int p, int current) {     int node_max = sizes[current] - sizes[node];     for (auto& target : (graph[node])) {       if (!processed[target] && target != p) {         node_max = max(node_max, sizes[target]);         select_cent(target, node, current);       }     }     if (node_max < cent_cost) {       cent = node;       cent_cost = node_max;     }   }   int process(int current) {     get_sizes(current, -1);     if (sizes[current] <= 1) return current;     cent = current;     cent_cost = ((int)1e9 + 10);     select_cent(current, -1, current);     int centroid = cent;     processed[centroid] = 1;     for (auto& target : (graph[centroid])) {       if (!processed[target]) {         int next_cent = process(target);         par_tree[next_cent] = centroid;       }     }     return centroid;   }   void update(int node) {     int cur = node;     while (cur > 0) {       mini[cur] = min(mini[cur], dist(cur, node));       cur = par_tree[cur];     }   }   int query(int node) {     int cur = node, ans = ((int)1e9 + 10);     while (cur > 0) {       ans = min(ans, mini[cur] + dist(node, cur));       cur = par_tree[cur];     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     for (int(i) = (0); (i) < (MAX); (i)++) mini[i] = ((int)1e9 + 10);     memset(par, -1, sizeof(par));     cin >> n >> m;     int a, b;     for (int(i) = (0); (i) < (n - 1); (i)++) {       cin >> a >> b;       graph[a].push_back(b);       graph[b].push_back(a);     }     lca_dfs(1, -1);     int root = process(1);     par_tree[root] = -1;     int type, node;     update(1);     for (int(k) = (0); (k) < (m); (k)++) {       cin >> type >> node;       if (type == 1) {         update(node);       } else {         cout << (query(node)) <<   n ;         ;       }     }   }   