#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   template <typename T>   T getint() {     T val = 0;     char c;     while ((c = getchar()) && !(c >=  0  && c <=  9 ))       ;     do {       val = (val * 10) + c -  0 ;     } while ((c = getchar()) && (c >=  0  && c <=  9 ));     return val;   }   const int maxn = 100001, hgt = 17;   int n, m;   vector<int> adj[maxn];   int par[maxn], b[maxn], lvl[maxn];   int dp[maxn][hgt];   void dfs_lca(int x, int p = -1, int lev = 0) {     b[x] = 1;     par[x] = p;     lvl[x] = lev;     for (auto i : adj[x]) {       if (!b[i]) {         dfs_lca(i, x, lev + 1);       }     }     b[x] = 2;   }   void init() {     memset(dp, -1, sizeof dp);     for (int i = 1; i <= n; ++i) {       dp[i][0] = par[i];     }     for (int j = 1; j < hgt; ++j) {       for (int i = 1; i <= n; ++i) {         if (dp[i][j - 1] != -1) {           dp[i][j] = dp[dp[i][j - 1]][j - 1];         }       }     }   }   int lca(int p, int q) {     if (lvl[p] > lvl[q]) swap(p, q);     for (int i = hgt - 1; i >= 0; i--) {       if (dp[q][i] != -1 && lvl[p] <= lvl[dp[q][i]]) q = dp[q][i];     }     if (p == q) return p;     for (int i = hgt - 1; i >= 0; i--) {       if (dp[q][i] != -1 && dp[q][i] != dp[p][i]) {         p = dp[p][i];         q = dp[q][i];       }     }     return dp[p][0];   }   int kth(int p, int k) {     for (int i = 0; i < hgt; ++i) {       if (k & (1 << i)) {         p = dp[p][i];       }     }     return p;   }   int dist(int a, int b) {     int l = lca(a, b);     return lvl[a] + lvl[b] - 2 * lvl[l];   }   int banned[maxn];   int b0[maxn], sz[maxn];   void dfs0(int x) {     b0[x] = 1;     sz[x] = 1;     for (auto i : adj[x]) {       if (b0[i] || banned[i]) continue;       dfs0(i);       sz[x] += sz[i];     }     b0[x] = 2;   }   int dfs1(int x, int p, int nn) {     int ind = -1;     for (auto i : adj[x]) {       if (banned[i] || i == p) continue;       if (sz[i] > nn / 2) ind = i;     }     if (ind != -1) return dfs1(ind, x, nn);     return x;   }   vector<int> cadj[maxn];   int cpar[maxn];   int decompose(int x = 1) {     memset(b0, 0, sizeof b0);     dfs0(x);     int centroid = dfs1(x, -1, sz[x]);     banned[centroid] = 1;     for (auto i : adj[centroid]) {       if (!banned[i]) {         int child = decompose(i);         cadj[centroid].push_back(child);         cpar[child] = centroid;       }     }     return centroid;   }   int main() {     n = getint<int>();     m = getint<int>();     for (int i = 1; i < n; ++i) {       int a, b;       a = getint<int>();       b = getint<int>();       adj[a].push_back(b);       adj[b].push_back(a);     }     dfs_lca(1);     init();     int root = decompose();     vector<int> ans(n + 1, 1e9);     for (int i = -1; i < m; ++i) {       int typ, v;       if (i >= 0) {         typ = getint<int>();         v = getint<int>();       } else {         typ = 1;         v = 1;       }       if (typ == 1) {         int akt = v;         while (akt) {           ans[akt] = min(ans[akt], dist(akt, v));           akt = cpar[akt];         }       } else {         int res = 1e9;         int akt = v;         while (akt) {           res = min(res, ans[akt] + dist(akt, v));           akt = cpar[akt];         }         printf( %d n , res);       }     }     return 0;   }