#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb insert
const int inf = 1e7;
const int LOGN = 18;
const int N = int(1e5) + 10;

int n,m,nn;
set<int> graph[N];
int dp[LOGN][N],depth[N],sub[N],ans[N],par[N];
void dfs2(int u,int p)
{
	for(int v:graph[u])
	{
		if(v==p) continue;
		dp[0][v] = u;
		depth[v] = depth[u]+1;
		dfs2(v,u);
	}
}
void preprocess()
{
	depth[1] = 0;
	dp[0][1] = 1;
	dfs2(1,0);
	for(int k=1;k<LOGN;k++)
		for(int i=1;i<=n;i++)
			dp[k][i] = dp[k-1][dp[k-1][i]];
}
int lca(int u,int v)
{
	if(depth[u]>depth[v])swap(u,v);
	int d = depth[v]-depth[u];
	for(int k=LOGN-1;k>=0;k--)
	{
		if(d&(1<<k))
			v = dp[k][v];
	}
	if(u==v)
		return u;
	for(int k=LOGN-1;k>=0;k--)
	{
		if(dp[k][u]!=dp[k][v])
			u=dp[k][u],v=dp[k][v];
	}
	return dp[0][u];
}
int dist(int a,int b)
{
	return depth[a]+depth[b]-2*depth[lca(a,b)];
}
//->centroid decomposition
void dfs(int u,int p)
{
	sub[u]=1;
	nn++;
	for(int v:graph[u])
	{
		if(v!=p)
			{dfs(v,u);sub[u]+=sub[v];}
	}
}
int dfs1(int u,int p)
{
	for(int v:graph[u])
		if(v!=p && sub[v]>nn/2)
			return dfs1(v,u);
	return u;
}
void decompose(int u,int p)
{
	nn = 0;
	dfs(u,0);
	int c = dfs1(u,0);
	if(p==0) p = c;
	par[c] = p;
	for(int v:graph[c])
	{
		graph[v].erase(c);
		decompose(v,c);
	}
	graph[c].clear();
}
//->Queries
void update(int u)
{
	int x = u;
	while(1)
	{
		ans[x] = min(ans[x],dist(x,u));
		if(x==par[x])
			return;
		x = par[x];
	}
}
int query(int u)
{
	int x = u,val=inf;
	while(1)
	{
		val = min(val,dist(u,x)+ans[x]);
		if(x==par[x])
			return val;
		x = par[x];
	}
}
int main()
{
	//freopen("inputf.txt","r",stdin);
	scanf("%d %d",&n,&m);
	for(int i=0;i<n-1;i++)
	{
		int u,v;
		scanf("%d %d",&u,&v);
		graph[u].pb(v);
		graph[v].pb(u);
	}
	preprocess();
	decompose(1,0);
	for(int i=1;i<=n;i++)
		ans[i] = inf;
	update(1);
	while(m--)
	{
		int t,v;
		scanf("%d %d",&t,&v);
		if(t==1)
			update(v);
		else
			printf("%d\n",query(v));
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
const int N = 100005;
const int inf = 1e7;

bool vis[N],centroid[N];
int subsize[N],c_depth[N],c_parent[N],ans[N],pa[N][21],depth[N];
vector<int> graph[N],c_graph[N];
void dfs(int u)
{
	vis[u] = 1;
	for(int v:graph[u])
	{
		if(!vis[v] && !centroid[v])
			{dfs(v);subsize[u]+=subsize[v];}
	}
	subsize[u]++;
}
int getCentroid(int u)
{
	int sz = subsize[u];
	int heavy_node;
	bool is;
	while(1)
	{
		is = 1;
		heavy_node = 0;
		vis[u]=1;
		for(int v:graph[u])
		{
			if(!vis[v] && !centroid[v])
			{
				if(subsize[v]>sz/2)
					is = 0;
				if(heavy_node==0 || subsize[v]>subsize[heavy_node])
					heavy_node = v;
			}
		}
		if(is)
			return u;
		u = heavy_node;
	}
}
int decompose(int u,int p)
{
	fill(vis,vis+N,0);
	fill(subsize,subsize+N,0);
	dfs(u);
	fill(vis,vis+N,0);
	int c = getCentroid(u);
	centroid[c]=1;
	c_depth[c] = c_depth[p]+1;
	c_parent[c] = p;
	for(int v:graph[c])
	{
		if(!centroid[v])
		{
			int cs = decompose(v,c);
			c_graph[cs].pb(c);
			c_graph[c].pb(cs);
		}
	}
	return c;
}
int c_lca(int u,int v)
{
	while(c_depth[u]<c_depth[v])
		v = c_parent[v];
	while(c_depth[u]>c_depth[v])
		u = c_parent[u];
	while(u!=v)
		u = c_parent[u],v = c_parent[v];
	return u;
}
void dfs2(int u,int p)
{
	depth[u] = depth[p]+1;
	pa[u][0] = p;
	for(int v:graph[u])
	{
		if(v==p) continue;
		dfs2(v,u);
	}
}
int pre(int n)
{
	for(int k=1;k<21;k++)
		for(int u=1;u<=n;u++)
			pa[u][k] = pa[pa[u][k-1]][k-1];
}
int lca(int u,int v)
{
	if(depth[u]>depth[v])
		swap(u,v);
	for(int k=20;k>=0;k--)
	{
		if(depth[pa[v][k]]>=depth[u])
			v = pa[v][k];
	}
	if(u==v)
		return u;
	for(int k=20;k>=0;k--)
	{
		if(pa[u][k]!=pa[v][k])
			u=pa[u][k],v=pa[v][k];
	}
	return pa[u][0];
}
int dist(int u,int v)
{
	return depth[u]+depth[v]-2*depth[lca(u,v)];
}
/*void dfs3(int u,int p)
{
	cout<<u<<endl;
	for(int v:c_graph[u])
	{
		if(v==p)continue;
		dfs3(v,u);
	}
}*/
int main()
{
	//freopen("inputf.txt","r",stdin);
	int n,m,u,v,t;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
		ans[i] = inf;
	for(int i=1;i<n;i++)
	{
		scanf("%d %d",&u,&v);
		graph[u].pb(v);
		graph[v].pb(u);
	}
	int c_root = decompose(1,0);
	dfs2(1,0);
	pre(n);
	ans[c_root] = min(ans[c_root],dist(1,c_root));
	int x = 1;
	while(x!=c_root)
	{
		ans[x] = min(ans[x],dist(x,1));
		x = c_parent[x];
	}
	while(m--)
	{
		scanf("%d %d",&t,&v);
		if(t==1)
		{
			ans[c_root] = min(ans[c_root],dist(v,c_root));
			int x = v;
			while(x!=c_root)
			{
				ans[x] = min(ans[x],dist(x,v));
				x = c_parent[x];
			}
		}
		else
		{
			int mini = dist(v,c_root)+ans[c_root];
			int x = v;
			while(x!=c_root)
			{
				mini = min(mini,dist(v,x)+ans[x]);
				x = c_parent[x];
			}
			printf("%d\n",mini);
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb insert
const int inf = 1e7;
const int LOGN = 18;
const int N = int(1e5) + 10;

int n,m,nn;
set<int> graph[N];
int dp[LOGN][N],depth[N],sub[N],ans[N],par[N];
void dfs2(int u,int p)
{
	for(int v:graph[u])
	{
		if(v==p) continue;
		dp[0][v] = u;
		depth[v] = depth[u]+1;
		dfs2(v,u);
	}
}
void preprocess()
{
	depth[1] = 0;
	dp[0][1] = 1;
	dfs2(1,0);
	for(int k=1;k<LOGN;k++)
		for(int i=1;i<=n;i++)
			dp[k][i] = dp[k-1][dp[k-1][i]];
}
int lca(int u,int v)
{
	if(depth[u]>depth[v])swap(u,v);
	int d = depth[v]-depth[u];
	for(int k=LOGN-1;k>=0;k--)
	{
		if(d&(1<<k))
			v = dp[k][v];
	}
	if(u==v)
		return u;
	for(int k=LOGN-1;k>=0;k--)
	{
		if(dp[k][u]!=dp[k][v])
			u=dp[k][u],v=dp[k][v];
	}
	return dp[0][u];
}
int dist(int a,int b)
{
	return depth[a]+depth[b]-2*depth[lca(a,b)];
}
//->centroid decomposition
void dfs(int u,int p)
{
	sub[u]=1;
	for(int v:graph[u])
	{
		if(v!=p)
			{dfs(v,u);sub[u]+=sub[v];}
	}
}
int dfs1(int u,int p)
{
	for(int v:graph[u])
		if(v!=p && sub[v]>nn/2)
			return dfs1(v,u);
	return u;
}
void decompose(int u,int p)
{
	nn = 0;
	dfs(u,0);
	int c = dfs1(u,0);
	if(p==0) p = c;
	par[c] = p;
	for(int v:graph[c])
	{
		graph[v].erase(c);
		decompose(v,c);
	}
	graph[c].clear();
}
//->Queries
void update(int u)
{
	int x = u;
	while(1)
	{
		ans[x] = min(ans[x],dist(x,u));
		if(x==par[x])
			break;
		x = par[x];
	}
}
int query(int u)
{
	int x = u;
	int ret=inf;
	while(1)
	{
		ret = min(ret,dist(u,x) + ans[x]);
		if(x==par[x])
			break;
		x = par[x];
	}
	return ret;
}
int main()
{
	//freopen("inputf.txt","r",stdin);
	scanf("%d %d",&n,&m);
	for(int i=0;i<n-1;i++)
	{
		int u,v;
		scanf("%d %d",&u,&v);
		graph[u].pb(v);
		graph[v].pb(u);
	}
	preprocess();
	decompose(1,0);
	for(int i=1;i<=n;i++)
		ans[i] = inf;
	update(1);
	while(m--)
	{
		int t,v;
		scanf("%d %d",&t,&v);
		if(t==1)
			update(v);
		else
			printf("%d\n",query(v));
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb insert
const int inf = 1e7;
const int LOGN = 18;
const int N = int(1e5) + 10;

int n,m,nn;
set<int> graph[N];
int dp[LOGN][N],depth[N],sub[N],ans[N],par[N];
void dfs2(int u,int p)
{
	for(int v:graph[u])
	{
		if(v==p) continue;
		dp[0][v] = u;
		depth[v] = depth[u]+1;
		dfs2(v,u);
	}
}
void preprocess()
{
	depth[1] = 0;
	dp[0][1] = 1;
	dfs2(1,0);
	for(int k=1;k<LOGN;k++)
		for(int i=1;i<=n;i++)
			dp[k][i] = dp[k-1][dp[k-1][i]];
}
int lca(int u,int v)
{
	if(depth[u]>depth[v])swap(u,v);
	int d = depth[v]-depth[u];
	for(int k=LOGN-1;k>=0;k--)
	{
		if(d&(1<<k))
			v = dp[k][v];
	}
	if(u==v)
		return u;
	for(int k=LOGN-1;k>=0;k--)
	{
		if(dp[k][u]!=dp[k][v])
			u=dp[k][u],v=dp[k][v];
	}
	return dp[0][u];
}
int dist(int a,int b)
{
	return depth[a]+depth[b]-2*depth[lca(a,b)];
}
//->centroid decomposition
void dfs(int u,int p)
{
	sub[u]=1;
	for(int v:graph[u])
	{
		if(v!=p)
			{dfs(v,u);sub[u]+=sub[v];}
	}
}
int dfs1(int u,int p)
{
	for(int v:graph[u])
		if(v!=p && sub[v]>nn/2)
			return dfs1(v,u);
	return u;
}
void decompose(int root,int p)
{
	nn=0;
	dfs(root,root);
	int centroid = dfs1(root,root);
	if(p==-1)p=centroid;
	par[centroid]=p;
	for(auto it=graph[centroid].begin();it!=graph[centroid].end();it++)
	{
		graph[*it].erase(centroid);
		decompose(*it,centroid);
	}
	graph[centroid].clear();
}
//->Queries
void update(int u)
{
	int x = u;
	while(1)
	{
		ans[x] = min(ans[x],dist(x,u));
		if(x==par[x])
			break;
		x = par[x];
	}
}
int query(int u)
{
	int x = u;
	int ret=inf;
	while(1)
	{
		ret = min(ret,dist(u,x) + ans[x]);
		if(x==par[x])
			break;
		x = par[x];
	}
	return ret;
}
int main()
{
	//freopen("inputf.txt","r",stdin);
	scanf("%d %d",&n,&m);
	for(int i=0;i<n-1;i++)
	{
		int u,v;
		scanf("%d %d",&u,&v);
		graph[u].pb(v);
		graph[v].pb(u);
	}
	preprocess();
	decompose(1,-1);
	for(int i=1;i<=n;i++)
		ans[i] = inf;
	update(1);
	while(m--)
	{
		int t,v;
		scanf("%d %d",&t,&v);
		if(t==1)
			update(v);
		else
			printf("%d\n",query(v));
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
const int N = 100005;
const int inf = 1e7;
bool deb = 0;

bool vis[N],centroid[N];
int subsize[N],c_depth[N],c_parent[N],ans[N],pa[N][18],depth[N];
vector<int> graph[N],c_graph[N];
void dfs(int u)
{
	vis[u] = 1;
	subsize[u] = 1;
	for(int v:graph[u])
	{
		if(!vis[v] && !centroid[v])
			{dfs(v);subsize[u]+=subsize[v];}
	}
}
int getCentroid(int u)
{
	int sz = subsize[u];
	int heavy_node;
	bool is;
	while(1)
	{
		if(deb)
			cout<<u<<endl;
		is = 1;
		heavy_node = 0;
		vis[u]=1;
		for(int v:graph[u])
		{
			if(!vis[v] && !centroid[v])
			{
				if(subsize[v]>sz/2)
					is = 0;
				if(heavy_node==0 || subsize[v]>subsize[heavy_node])
					heavy_node = v;
			}
		}
		if(is && sz-subsize[u]<=sz/2)
			return u;
		u = heavy_node;
	}
}
int decompose(int u,int p)
{
	fill(vis,vis+N,0);
	fill(subsize,subsize+N,0);
	dfs(u);
	fill(vis,vis+N,0);
	int c = getCentroid(u);
	centroid[c]=1;
	c_depth[c] = c_depth[p]+1;
	c_parent[c] = p;
	for(int v:graph[c])
	{
		if(v==p)continue;
		int cs = decompose(v,c);
		c_graph[cs].pb(c);
		c_graph[c].pb(cs);
	}
	return c;
}
int c_lca(int u,int v)
{
	while(c_depth[u]<c_depth[v])
		v = c_parent[v];
	while(c_depth[u]>c_depth[v])
		u = c_parent[u];
	while(u!=v)
		u = c_parent[u],v = c_parent[v];
	return u;
}
void dfs2(int u,int p)
{
	depth[u] = depth[p]+1;
	pa[u][0] = p;
	for(int v:graph[u])
	{
		if(v==p) continue;
		dfs2(v,u);
	}
}
int pre(int n)
{
	for(int k=1;k<18;k++)
		for(int u=1;u<=n;u++)
			pa[u][k] = pa[pa[u][k-1]][k-1];
}
int lca(int u,int v)
{
	if(depth[u]>depth[v])
		swap(u,v);
	for(int k=17;k>=0;k--)
	{
		if(depth[pa[v][k]]>=depth[u])
			v = pa[v][k];
	}
	if(u==v)
		return u;
	for(int k=17;k>=0;k--)
	{
		if(pa[u][k]!=pa[v][k])
			u=pa[u][k],v=pa[v][k];
	}
	return pa[u][0];
}
int dist(int u,int v)
{
	return depth[u]+depth[v]-2*depth[lca(u,v)];
}
/*void dfs3(int u,int p)
{
	cout<<u<<endl;
	for(int v:c_graph[u])
	{
		if(v==p)continue;
		dfs3(v,u);
	}
}*/
int main()
{
	//freopen("inputf.txt","r",stdin);
	int n,m,u,v,t;
	scanf("%d %d",&n,&m);
	if(n==100000 && m==100000)
		deb = 1;
	for(int i=1;i<=n;i++)
		ans[i] = inf;
	for(int i=1;i<n;i++)
	{
		scanf("%d %d",&u,&v);
		graph[u].pb(v);
		graph[v].pb(u);
	}
	int c_root = decompose(1,0);
	dfs2(1,0);
	pre(n);
	ans[c_root] = min(ans[c_root],dist(1,c_root));
	int x = 1;
	while(x!=c_root)
	{
		ans[x] = min(ans[x],dist(x,1));
		x = c_parent[x];
	}
	while(m--)
	{
		scanf("%d %d",&t,&v);
		if(t==1)
		{
			ans[c_root] = min(ans[c_root],dist(v,c_root));
			int x = v;
			while(x!=c_root)
			{
				ans[x] = min(ans[x],dist(x,v));
				x = c_parent[x];
			}
		}
		else
		{
			int mini = dist(v,c_root)+ans[c_root];
			int x = v;
			while(x!=c_root)
			{
				mini = min(mini,dist(v,x)+ans[x]);
				x = c_parent[x];
			}
			printf("%d\n",mini);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
const int inf = 1e7;
const int LOGN = 18;
const int N = int(1e5) + 10;

int n,m,nn;
vector<int> graph[N];
bool centroid[N];
int dp[LOGN][N],depth[N],sub[N],ans[N],par[N];
void dfs2(int u,int p)
{
    for(int v:graph[u])
    {
        if(v==p) continue;
        dp[0][v] = u;
        depth[v] = depth[u]+1;
        dfs2(v,u);
    }
}
void preprocess()
{
    depth[1] = 0;
    dp[0][1] = 1;
    dfs2(1,0);
    for(int k=1;k<LOGN;k++)
        for(int i=1;i<=n;i++)
            dp[k][i] = dp[k-1][dp[k-1][i]];
}
int lca(int u,int v)
{
    if(depth[u]>depth[v])swap(u,v);
    int d = depth[v]-depth[u];
    for(int k=LOGN-1;k>=0;k--)
    {
        if(d&(1<<k))
            v = dp[k][v];
    }
    if(u==v)
        return u;
    for(int k=LOGN-1;k>=0;k--)
    {
        if(dp[k][u]!=dp[k][v])
            u=dp[k][u],v=dp[k][v];
    }
    return dp[0][u];
}
int dist(int a,int b)
{
    return depth[a]+depth[b]-2*depth[lca(a,b)];
}
//->centroid decomposition
void dfs(int u,int p)
{
    sub[u]=1;
    nn++;
    for(int v:graph[u])
    {
        if(!centroid[v] && v!=p)
            {dfs(v,u);sub[u]+=sub[v];}
    }
}
int dfs1(int u,int p)
{
    for(int v:graph[u])
        if(!centroid[v] && v!=p && sub[v]>nn/2)
            return dfs1(v,u);
    return u;
}
void decompose(int u,int p)
{
    nn = 0;
    dfs(u,0);
    int c = dfs1(u,0);
    centroid[c] = 1;
    if(p==0) p = c;
    par[c] = p;
    for(int v:graph[c])
    {
        if(!centroid[v])
        {
        decompose(v,c);
        }
    }
}
//->Queries
void update(int u)
{
    int x = u;
    while(1)
    {
        ans[x] = min(ans[x],dist(x,u));
        if(x==par[x])
            return;
        x = par[x];
    }
}
int query(int u)
{
    int x = u,val=inf;
    while(1)
    {
        val = min(val,dist(u,x)+ans[x]);
        if(x==par[x])
            return val;
        x = par[x];
    }
}
int main()
{
    //freopen("inputf.txt","r",stdin);
    scanf("%d %d",&n,&m);
    for(int i=0;i<n-1;i++)
    {
        int u,v;
        scanf("%d %d",&u,&v);
        graph[u].pb(v);
        graph[v].pb(u);
    }
    preprocess();
    decompose(1,0);
    for(int i=1;i<=n;i++)
        ans[i] = inf;
    update(1);
    while(m--)
    {
        int t,v;
        scanf("%d %d",&t,&v);
        if(t==1)
            update(v);
        else
            printf("%d\n",query(v));
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
#define FOR(i,j,k) for(int i =j; i<=k ;i++)
const int maxn = 100010;
int fa[maxn][22], deep[maxn], ans[maxn];
vector<int> G[maxn], red;
void dfs(int u, int f)
{
    FOR(i, 0, G[u].size() -1)
    {
        int v = G[u][i];
        if(v != f)
        {
            fa[v][0] = u;
            deep [v] = deep[u] +1;
            ans[v] =deep[v]-1;
            dfs( v, u);
        }
    }
}
void init( int n)
{
    FOR(i, 1, 20)
    FOR(j, 1, n)
    fa[j][i] = fa[ fa[j][ i-1]][ i-1];
}
int lca(int u, int v)
{
    if(deep[u] < deep[v]) swap(u ,v);
    int d = deep[u] - deep[v];
    FOR(i, 0, 20 )
    if((1 << i) &d)
        u = fa[u][i];
    if(u == v) return  v;
    for(int i = 20 ; i>=0 ;i--)
    {
        if(fa[u][i]  != fa[v][i])
        {
            u = fa[u][i];
            v = fa[v][i];
        }
    }
    return fa[u] [0];
}

void bfs()
{
    queue<int>q;
    FOR(i, 0, red.size()-1)
    {
        int u =red[i];
        q.push(u);
        ans [u] =0;
    }
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        FOR(i, 0, G[u].size() -1)
        {
            int v = G[u][i];
            if(ans[v] > ans[u]+1 )
            {
                ans[v] = ans[u] +1;
                q.push( v);
            }
        }
    }
}
int main()
{
    int n, m;
    scanf( "%d%d" ,& n, &m);
    FOR(i, 1, n) G[i].clear();

    FOR(i, 1, n-1)
    {
        int u ,vv;
        scanf("%d%d" ,&u, &vv);
        G[u] . push_back(vv);
        G[vv] .push_back(u);
    }
    deep[1] = 1;
    ans[1] = 0;

    dfs(1 , 0);
    init(n);
    red.push_back(1);

    FOR(i, 1, m)
    {
        int op, x;
        scanf("%d%d" ,&op, &x);
        if(op == 1)
        {
            red.push_back(x);
            if(red.size() == 300){
                bfs();
                red.clear();
            }
        }
        else{
            int ret = ans[x];
            if(red.size() >0)
                FOR(j, 0, red.size() -1)
            {
                ret = min(ret ,deep[x] + deep[red[j]]-2*deep[lca(x , red[j])]);
            }
            printf("%d\n", ret);
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
const int maxn = 100010;
int n, pre[maxn][22], d[maxn], ansd[maxn];
vector<int> nd[maxn], oper;
void init(){
    for(int i = 1; i <= n; i++) nd[i].clear();
    oper.clear();
    memset(pre, 0, sizeof(pre));
    d[0] = 0;
}

void dfs(int u, int fa)
{
    d[u] = d[fa]+1;
    ansd[u] = d[u] - 1;
    pre[u][0] = fa;
    for(int i = 0; i < nd[u].size(); i++)
        if(nd[u][i] != fa)  dfs(nd[u][i], u);
}

void lca_init()
{
    for(int i = 1; i <= 20; i++)
        for(int u = 1; u <= n;u++)
            pre[u][i] = pre[pre[u][i-1]][i-1];
}

int lca(int x, int y)
{
    if(x == y) return x;
    if(d[x] > d[y]) swap(x, y);

    for(int i = 20; i >= 0; i--)
        if(d[pre[y][i]] > d[x]) y = pre[y][i];
    if(pre[y][0] == x) return x;

    if(d[x] < d[y] ) y = pre[y][0];

    for(int i = 20; i >= 0; i--)
        if(pre[x][i] != pre[y][i]) {
            x = pre[x][i];
            y = pre[y][i];
        }
    return pre[x][0];
}
void bfs()
{
    queue<int> ndq;
    for(int i = 0; i < oper.size(); i++)
        ndq.push(oper[i]), ansd[oper[i]] = 0;
    oper.clear();
    int now;
    while(!ndq.empty())
    {
        now = ndq.front();
        ndq.pop();
        for(int i = 0; i < nd[now].size(); i++)
            if(ansd[nd[now][i]] > ansd[now] + 1) {
                ansd[nd[now][i]] = ansd[now] + 1;
                ndq.push( nd[now][i] );
            }
    }
}
int main()
{
    init();
    int q;
    cin>>n>>q;
    int Magic = 300;
    for(int i = 1; i < n; i++) {
        int a, b;
        cin>>a>>b;
        nd[a].push_back(b);
        nd[b].push_back(a);
    }

    dfs(1, 0);
    lca_init();
    int x, y;

    while(q--){
        cin>>x>>y;
        if(x == 1) {
            oper.push_back(y);
            if(oper.size() == Magic) bfs();
        }
        else if(x == 2){
            int ret = ansd[y];
            for(int i = 0; i < oper.size(); i++) {
                int anc = lca(y, oper[i]);
                ret = min(ret, d[y] + d[oper[i]] - 2 * d[anc]);
            }
            cout<<ret<<endl;
        }
    }

    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
#define FOR(i,j,k) for(int i =j; i<=k ;i++)
const int maxn = 100010;
int fa[maxn][22], deep[maxn], ans[maxn];
vector<int> G[maxn], red;
void dfs(int u, int f)
{
    deep[u] = deep[f]+1;
    ans[u] = deep[u] - 1;
    fa[u][0] = f;
    for(int i = 0; i < G[u].size(); i++)
        if(G[u][i] != f)  dfs(G[u][i], u);
}
void init(int n)
{
    for(int i = 1; i <= 20; i++)
        for(int u = 1; u <= n;u++)
            fa[u][i] = fa[fa[u][i-1]][i-1];
}
int lca(int x, int y)
{
    if(x == y) return x;
    if(deep[x] > deep[y]) swap(x, y);

    for(int i = 20; i >= 0; i--)
        if(deep[fa[y][i]] > deep[x]) y = fa[y][i];
    if(fa[y][0] == x) return x;

    if(deep[x] < deep[y] ) y = fa[y][0];

    for(int i = 20; i >= 0; i--)
        if(fa[x][i] != fa[y][i]) {
            x = fa[x][i];
            y = fa[y][i];
        }
    return fa[x][0];
}
void bfs()
{
    queue<int> ndq;
    for(int i = 0; i < red.size(); i++)
        ndq.push(red[i]), ans[red[i]] = 0;
    red.clear();
    int now;
    while(!ndq.empty())
    {
        now = ndq.front();
        ndq.pop();
        for(int i = 0; i < G[now].size(); i++)
            if(red[G[now][i]] > ans[now] + 1) {
                ans[G[now][i]] = ans[now] + 1;
                ndq.push( G[now][i] );
            }
    }
}
int main()
{
    int n, m;
    scanf( "%d%d" ,& n, &m);

    FOR(i, 1, n) G[i].clear();
    red.clear();
    memset(fa, 0, sizeof(fa));

    FOR(i, 1, n-1)
    {
        int u ,vv;
        scanf("%d%d" ,&u, &vv);
        G[u] . push_back(vv);
        G[vv] .push_back(u);
    }

    deep[0] = 0;
    //ans[1] = 0;

    dfs(1 , 0);
    init(n);

    FOR(i, 1, m)
    {
        int op, x;
        scanf("%d%d" ,&op, &x);
        if(op == 1)
        {
            red.push_back(x);
            if(red.size() == 300){
                bfs();
                //red.clear();
            }
        }
        else{
            if(red.size() >=1){
                FOR(j, 0, red.size() -1)
                {
                    ans[x] = min(ans[x] ,deep[x] + deep[red[j]] -2*deep[lca(x , red[j])]);
                }
            }
            printf("%d\n", ans[x]);
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
#define FOR(i,j,k) for(int i =j; i<=k ;i++)
const int maxn  =1e5+10;
vector<int>G[maxn];
int ans[maxn];
vector<int>red;
int deep[maxn];
int md =22;
int fa[maxn][22];
void dfs(int u, int f)
{
    FOR(i, 0, G[u].size() -1)
    {
        int v = G[u][i];
        if(v != f)
        {
            fa[v][0] = u;
            deep [v] = deep[u] +1;
            dfs( v, u);
        }
    }
}
void init( int n)
{
    FOR(i, 1, 20)
        FOR(j, 1, n)
            fa[j][i] = fa[ fa[j][ i-1]][ i-1];
}
int lca(int u, int v)
{
    if(deep[u] < deep[v]) swap(u ,v);
    int d = deep[u] - deep[v];
    FOR(i, 0, md-1)
        if((1 << i) &d)
            u = fa[u][i];
    if(u == v) return  v;
    for(int i = 20 ; i>=0 ;i--)
    {
        if(fa[u][i]  != fa[v][i])
        {
            u = fa[u][i];
            v = fa[v][i];
        }
    }
    return fa[u] [0];
}

void bfs()
{
    queue<int>q;
    FOR(i, 0, red.size()-1)
    {
        int u =red[i];
        q.push(u);
        ans [u] =0;
    }
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        FOR(i, 0, G[u].size() -1)
        {
            if(ans[G[u][i]] > ans[u]+1 )
            {
                ans[G[u][i]] = ans[u] +1;
                q.push( G[u][i]);
            }
        }
    }
}
int main()
{
    int n, m;
    scanf( "%d%d" ,& n, &m);
    FOR(i, 1, n) G[i].clear();

    FOR(i, 1, n-1)
    {
        int u ,vv;
        scanf("%d%d" ,&u, &vv);
        G[u] . push_back(vv);
        G[vv] .push_back(u);
    }
    deep[1] = 1;
    dfs(1 , -1);
    init(n);
    red.push_back(1);
    FOR(i, 1, n) ans[i] = n+2;
    ans[1] = 0;
    FOR(i, 1, m)
    {
        int op, x;
        scanf("%d%d" ,&op, &x);
        if(op == 1)
        {
            red.push_back(x);
            if(red.size() >= 300){
                bfs();
                red.clear();
            }
        }
        else{
            FOR(i, 0, red.size() -1)
            {
                //cout<<x<<"asdf"<<red[i]<<endl;
                //cout<<ans[x] << " "<<lca(x, red[i])<<endl;
                ans[x] = min(ans[x] ,deep[x] + deep[red[i]] -2*deep[lca(x , red[i])]);
            }
            printf("%d\n", ans[x]);
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
#define FOR(i,j,k) for(int i =j; i<=k ;i++)
const int maxn  =1e5+10;
vector<int>G[maxn];
vector<int>red;
int deep[maxn];
int md =22;
int fa[maxn][22];
void dfs(int u, int f)
{
    FOR(i, 0, G[u].size() -1)
    {
        int v = G[u][i];
        if(v != f)
        {
            fa[v][0] = u;
            deep [v] = deep[u] +1;
            dfs( v, u);
        }
    }
}
void init( int n)
{
    FOR(i, 1, md-1)
        FOR(j, 1, n)
            fa[j][i] = fa[ fa[j][ i-1]][ i-1];
}
int lca(int u, int v)
{
    if(deep[u] < deep[v]) swap(u ,v);
    int a = u,b= v;
    int d = deep[u] - deep[v];
    FOR(i, 0, md-1)
        if((1 << i) &d)
            u = fa[u][i];
    if(u == v) return  deep[a] - deep[v];
    for(int i = md -1 ; i>=0 ;i--)
    {
        if(fa[u][i]  != fa[v][i])
        {
            u = fa[u][i];
            v = fa[v][i];
        }
    }
    u = fa[u][0];

    return deep[a] - deep[u] + deep[b]-deep[u];
}
int ans[maxn];
void bfs()
{
    queue<int>q;
    FOR(i, 0, red.size()-1)
    {
        int u =red[i];
        q.push(u);
        ans [u] =0;
    }
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        FOR(i, 0, G[u].size() -1)
        {
            if(ans[G[u][i]] > ans[u]+1 )
            {
                ans[G[u][i]] = ans[u] +1;
                q.push( G[u][i]);
            }
        }
    }
}
int main()
{
    int n, m;
    scanf( "%d%d" ,& n, &m);
    FOR(i, 1, n-1)
    {
        int u ,vv;
        scanf("%d%d" ,&u, &vv);
        G[u] . push_back(vv);
        G[vv] .push_back(u);
    }
    deep[1] = 1;
    dfs(1 , -1);
    init(n);
    red.push_back(1);
    FOR(i, 1, n) ans[i] = n+2;
    ans[1] = 0;
    FOR(i, 1, m)
    {
        int op, x;
        scanf("%d%d" ,&op, &x);
        if(op == 1)
        {
            red.push_back(x);
            if(red.size() >= 300){
                bfs();
                red.clear();
            }
        }
        else{
            FOR(i, 0, red.size() -1)
            {
                //cout<<x<<"asdf"<<red[i]<<endl;
                //cout<<ans[x] << " "<<lca(x, red[i])<<endl;
                ans[x] = min(ans[x] ,lca(x , red[i]));
            }
            printf("%d\n", ans[x]);
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
#define FOR(i,j,k) for(int i =j; i<=k ;i++)
const int maxn = 100010;
int fa[maxn][22], deep[maxn], ans[maxn];
vector<int> G[maxn], red;
void dfs(int u, int f)
{
    deep[u] = deep[f]+1;
    ans[u] = deep[u] - 1;
    fa[u][0] = f;
    for(int i = 0; i < G[u].size(); i++)
        if(G[u][i] != f)  dfs(G[u][i], u);
}
void init( int n)
{
    FOR(i, 1, 20)
        FOR(j, 1, n)
            fa[j][i] = fa[ fa[j][ i-1]][ i-1];
}
int lca(int x, int y)
{
    if(x == y) return x;
    if(deep[x] > deep[y]) swap(x, y);

    for(int i = 20; i >= 0; i--)
        if(deep[fa[y][i]] > deep[x]) y = fa[y][i];
    if(fa[y][0] == x) return x;

    if(deep[x] < deep[y] ) y = fa[y][0];

    for(int i = 20; i >= 0; i--)
        if(fa[x][i] != fa[y][i]) {
            x = fa[x][i];
            y = fa[y][i];
        }
    return fa[x][0];
}

void bfs()
{
    queue<int>q;
    FOR(i, 0, red.size()-1)
    {
        int u =red[i];
        q.push(u);
        ans [u] =0;
    }
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        FOR(i, 0, G[u].size() -1)
        {
            int v = G[u][i];
            if(ans[v] > ans[u]+1 )
            {
                ans[v] = ans[u] +1;
                q.push( v);
            }
        }
    }
}
int main()
{
    int n, m;
    scanf( "%d%d" ,& n, &m);

    FOR(i, 1, n) G[i].clear();
    red.clear();
    memset(fa, 0, sizeof(fa));

    FOR(i, 1, n-1)
    {
        int u ,vv;
        scanf("%d%d" ,&u, &vv);
        G[u] . push_back(vv);
        G[vv] .push_back(u);
    }

    deep[0] = 0;
    //ans[1] = 0;

    dfs(1 , 0);
    init(n);

    FOR(i, 1, m)
    {
        int op, x;
        scanf("%d%d" ,&op, &x);
        if(op == 1)
        {
            red.push_back(x);
            if(red.size() == 300){
                bfs();
                red.clear();
            }
        }
        else{
            if(red.size() >=1){
            FOR(j, 0, red.size() -1)
            {//cout<<"sd";

                ans[x] = min(ans[x] ,deep[x] + deep[red[j]] -2*deep[lca(x , red[j])]);
            }}
            printf("%d\n", ans[x]);
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
#define FOR(i,j,k) for(int i =j; i<=k ;i++)
const int maxn = 100010;
int fa[maxn][22], deep[maxn], ans[maxn];
vector<int> G[maxn], red;
void dfs(int u, int f)
{
    FOR(i, 0, G[u].size() -1)
    {
        int v = G[u][i];
        if(v != f)
        {
            fa[v][0] = u;
            deep [v] = deep[u] +1;
            dfs( v, u);
        }
    }
}
void init( int n)
{
    FOR(i, 1, 20)
        FOR(j, 1, n)
            fa[j][i] = fa[ fa[j][ i-1]][ i-1];
}
int lca(int u, int v)
{
    if(deep[u] < deep[v]) swap(u ,v);
    int d = deep[u] - deep[v];
    FOR(i, 0, 20 )
        if((1 << i) &d)
            u = fa[u][i];
    if(u == v) return  v;
    for(int i = 20 ; i>=0 ;i--)
    {
        if(fa[u][i]  != fa[v][i])
        {
            u = fa[u][i];
            v = fa[v][i];
        }
    }
    return fa[u] [0];
}

void bfs()
{
    queue<int>q;
    FOR(i, 0, red.size()-1)
    {
        int u =red[i];
        q.push(u);
        ans [u] =0;
    }
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        FOR(i, 0, G[u].size() -1)
        {
            int v = G[u][i];
            if(ans[v] > ans[u]+1 )
            {
                ans[v] = ans[u] +1;
                q.push( v);
            }
        }
    }
}
int main()
{
    int n, m;
    scanf( "%d%d" ,& n, &m);
    FOR(i, 1, n) G[i].clear();

    FOR(i, 1, n-1)
    {
        int u ,vv;
        scanf("%d%d" ,&u, &vv);
        G[u] . push_back(vv);
        G[vv] .push_back(u);
    }
    deep[1] = 1;
    dfs(1 , 0);
    init(n);
    red.push_back(1);
    FOR(i, 1, n) ans[i] = n+2;
    ans[1] = 0;
    FOR(i, 1, m)
    {
        int op, x;
        scanf("%d%d" ,&op, &x);
        if(op == 1)
        {
            red.push_back(x);
            if(red.size() >= 300){
                bfs();
                red.clear();
            }
        }
        else{
            FOR(i, 0, red.size() -1)
            {
                //cout<<x<<"asdf"<<red[i]<<endl;
                //cout<<ans[x] << " "<<lca(x, red[i])<<endl;
                ans[x] = min(ans[x] ,deep[x] + deep[red[i]] -2*deep[lca(x , red[i])]);
            }
            printf("%d\n", ans[x]);
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
#define FOR(i,j,k) for(int i =j; i<=k ;i++)
const int maxn  =1e5+10;
vector<int>G[maxn];
vector<int>red;
int deep[maxn];
int md =22;
int fa[maxn][22];
void dfs(int u, int f)
{
    FOR(i, 0, G[u].size() -1)
    {
        int v = G[u][i];
        if(v != f)
        {
            fa[v][0] = u;
            deep [v] = deep[u] +1;
            dfs( v, u);
        }
    }
}
void init( int n)
{
    FOR(i, 1, md-1)
        FOR(j, 1, n)
            fa[j][i] = fa[ fa[j][ i-1]][ i-1];
}
int lca(int u, int v)
{
    if(deep[u] < deep[v]) swap(u ,v);
    int a = u,b= v;
    int d = deep[u] - deep[v];
    FOR(i, 0, md-1)
        if((1 << i) &d)
            u = fa[u][i];
    if(u == v) return  deep[a] - deep[v];
    for(int i = md -1 ; i>=0 ;i--)
    {
        if(fa[u][i]  != fa[v][i])
        {
            u = fa[u][i];
            v = fa[v][i];
        }
    }
    u = fa[u][0];

    return deep[a] - deep[u] + deep[b]-deep[u];
}
int ans[maxn];
void bfs()
{
    queue<int>q;
    FOR(i, 0, red.size()-1)
    {
        int u =red[i];
        q.push(u);
        ans [u] =0;
    }
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        FOR(i, 0, G[u].size() -1)
        {
            if(ans[G[u][i]] < ans[u]+1 )
            {
                ans[G[u][i]] = ans[u] +1;
                q.push( G[u][i]);
            }
        }
    }
}
int main()
{
    int n, m;
    scanf( "%d%d" ,& n, &m);
    FOR(i, 1, n-1)
    {
        int u ,vv;
        scanf("%d%d" ,&u, &vv);
        G[u] . push_back(vv);
        G[vv] .push_back(u);
    }
    deep[1] = 1;
    dfs(1 , -1);
    init(n);
    red.push_back(1);
    FOR(i, 1, n) ans[i] = n+2;
    ans[1] = 0;
    FOR(i, 1, m)
    {
        int op, x;
        scanf("%d%d" ,&op, &x);
        if(op == 1)
        {
            red.push_back(x);
            if(red.size() >= 300){
                bfs();
                red.clear();
            }
        }
        else{
            FOR(i, 0, red.size() -1)
            {
                //cout<<x<<"asdf"<<red[i]<<endl;
                //cout<<ans[x] << " "<<lca(x, red[i])<<endl;
                ans[x] = min(ans[x] ,lca(x , red[i]));
            }
            printf("%d\n", ans[x]);
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
#define FOR(i,j,k) for(int i =j; i<=k ;i++)
const int maxn = 100010;
int n, pre[maxn][22], d[maxn], ansd[maxn];
vector<int> nd[maxn], oper;
void init(){
    for(int i = 1; i <= n; i++) nd[i].clear();
    oper.clear();
    memset(pre, 0, sizeof(pre));
    d[0] = 0;
}

void dfs(int u, int fa)
{
    d[u] = d[fa]+1;
    ansd[u] = d[u] - 1;
    pre[u][0] = fa;
    for(int i = 0; i < nd[u].size(); i++)
        if(nd[u][i] != fa)  dfs(nd[u][i], u);
}

void lca_init()
{
    for(int i = 1; i <= 20; i++)
        for(int u = 1; u <= n;u++)
            pre[u][i] = pre[pre[u][i-1]][i-1];
}

int lca(int x, int y)
{
    if(x == y) return x;
    if(d[x] > d[y]) swap(x, y);

    for(int i = 20; i >= 0; i--)
        if(d[pre[y][i]] > d[x]) y = pre[y][i];
    if(pre[y][0] == x) return x;

    if(d[x] < d[y] ) y = pre[y][0];

    for(int i = 20; i >= 0; i--)
        if(pre[x][i] != pre[y][i]) {
            x = pre[x][i];
            y = pre[y][i];
        }
    return pre[x][0];
}
void bfs()
{
    queue<int> ndq;
    for(int i = 0; i < oper.size(); i++)
        ndq.push(oper[i]), ansd[oper[i]] = 0;
    oper.clear();
    int now;
    while(!ndq.empty())
    {
        now = ndq.front();
        ndq.pop();
        for(int i = 0; i < nd[now].size(); i++)
            if(ansd[nd[now][i]] > ansd[now] + 1) {
                ansd[nd[now][i]] = ansd[now] + 1;
                ndq.push( nd[now][i] );
            }
    }
}

int main()
{
    int n, m;
    scanf( "%d%d" ,& n, &m);

    FOR(i, 1, n) nd[i].clear();
    oper.clear();
    memset(pre, 0, sizeof(pre));

    FOR(i, 1, n-1)
    {
        int u ,vv;
        scanf("%d%d" ,&u, &vv);
        nd[u] . push_back(vv);
        nd[vv] .push_back(u);
    }

    d[0] = 0;
    //ans[1] = 0;

    dfs(1 , 0);
    lca_init();

    while( m--)
    {
        int op, x;
        scanf("%d%d" ,&op, &x);
        if(op == 1)
        {
            oper.push_back(x);
            if(oper.size() == 300){
                bfs();
                //red.clear();
            }
        }
        else{
            int ret = ansd[x];
            if(oper.size() >=1){
                FOR(i, 0, oper.size() -1)
                {
                    ret = min(ret ,d[x] + d[oper[i]] -2*d[lca(x , oper[i])]);
                }
            }
            printf("%d\n", ret);
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
#define FOR(i,j,k) for(int i =j; i<=k ;i++)
const int maxn = 100010;
int fa[maxn][22], deep[maxn], ans[maxn];
vector<int> G[maxn], red;
void dfs(int u, int f)
{
    deep[u] = deep[f]+1;
    ans[u] = deep[u] - 1;
    fa[u][0] = f;
    for(int i = 0; i < G[u].size(); i++)
        if(G[u][i] != f)  dfs(G[u][i], u);
}
void init(int n)
{
    for(int i = 1; i <= 20; i++)
        for(int u = 1; u <= n;u++)
            fa[u][i] = fa[fa[u][i-1]][i-1];
}
int lca(int x, int y)
{
    if(x == y) return x;
    if(deep[x] > deep[y]) swap(x, y);

    for(int i = 20; i >= 0; i--)
        if(deep[fa[y][i]] > deep[x]) y = fa[y][i];
    if(fa[y][0] == x) return x;

    if(deep[x] < deep[y] ) y = fa[y][0];

    for(int i = 20; i >= 0; i--)
        if(fa[x][i] != fa[y][i]) {
            x = fa[x][i];
            y = fa[y][i];
        }
    return fa[x][0];
}
void bfs()
{
    queue<int> ndq;
    for(int i = 0; i < red.size(); i++)
        ndq.push(red[i]), ans[red[i]] = 0;
    red.clear();
    int now;
    while(!ndq.empty())
    {
        now = ndq.front();
        ndq.pop();
        for(int i = 0; i < G[now].size(); i++)
            if(red[G[now][i]] > ans[now] + 1) {
                ans[G[now][i]] = ans[now] + 1;
                ndq.push( G[now][i] );
            }
    }
}
int main()
{
    int n, m;
    scanf( "%d%d" ,& n, &m);

    FOR(i, 1, n) G[i].clear();
    red.clear();
    memset(fa, 0, sizeof(fa));

    FOR(i, 1, n-1)
    {
        int u ,vv;
        scanf("%d%d" ,&u, &vv);
        G[u] . push_back(vv);
        G[vv] .push_back(u);
    }

    deep[0] = 0;

    dfs(1 , 0);
    init(n);

    FOR(i, 1, m)
    {
        int op, x;
        scanf("%d%d" ,&op, &x);
        if(op == 1)
        {

            red.push_back(x);
            if(red.size() == 300){
                bfs();
                //red.clear();
            }
        }
        else{
            //if(red.size() >=1){
                FOR(j, 0, red.size() -1)
                {
                    int anc = lca(ans[x] , red[j]);
                    ans[x] = min(ans[x] ,deep[x] + deep[red[j]] -2*deep[anc]);
                }
            //}
            printf("%d\n", ans[x]);
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
#define FOR(i,j,k) for(int i =j; i<=k ;i++)
const int maxn = 100010;
int fa[maxn][22], deep[maxn], ans[maxn];
vector<int> G[maxn], red;
void dfs(int u, int f)
{
    FOR(i, 0, G[u].size() -1)
    {
        int v = G[u][i];
        if(v != f)
        {
            fa[v][0] = u;
            deep [v] = deep[u] +1;
            ans[v] =deep[v]-1;
            dfs( v, u);
        }
    }
}
void init( int n)
{
    FOR(i, 1, 20)
        FOR(j, 1, n)
            fa[j][i] = fa[ fa[j][ i-1]][ i-1];
}
int lca(int u, int v)
{
    if(deep[u] < deep[v]) swap(u ,v);
    int d = deep[u] - deep[v];
    FOR(i, 0, 20 )
        if((1 << i) &d)
            u = fa[u][i];
    if(u == v) return  v;
    for(int i = 20 ; i>=0 ;i--)
    {
        if(fa[u][i]  != fa[v][i])
        {
            u = fa[u][i];
            v = fa[v][i];
        }
    }
    return fa[u] [0];
}

void bfs()
{
    queue<int>q;
    FOR(i, 0, red.size()-1)
    {
        int u =red[i];
        q.push(u);
        ans [u] =0;
    }
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        FOR(i, 0, G[u].size() -1)
        {
            int v = G[u][i];
            if(ans[v] > ans[u]+1 )
            {
                ans[v] = ans[u] +1;
                q.push( v);
            }
        }
    }
}
int main()
{
    int n, m;
    scanf( "%d%d" ,& n, &m);
    FOR(i, 1, n) G[i].clear();

    FOR(i, 1, n-1)
    {
        int u ,vv;
        scanf("%d%d" ,&u, &vv);
        G[u] . push_back(vv);
        G[vv] .push_back(u);
    }
    deep[1] = 1;
    ans[1] = 0;

    dfs(1 , 0);
    init(n);
    red.push_back(1);

    FOR(i, 1, m)
    {
        int op, x;
        scanf("%d%d" ,&op, &x);
        if(op == 1)
        {
            red.push_back(x);
            if(red.size() == 300){
                bfs();
                red.clear();
            }
        }
        else{
            FOR(i, 0, red.size() -1)
            {

                ans[x] = min(ans[x] ,deep[x] + deep[red[i]] -2*deep[lca(x , red[i])]);
            }
            printf("%d\n", ans[x]);
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
#define FOR(i,j,k) for(int i =j; i<=k ;i++)
const int maxn = 100010;
int fa[maxn][22], deep[maxn], ans[maxn];
vector<int> G[maxn], red;
void dfs(int u, int f)
{
    FOR(i, 0, G[u].size() -1)
    {
        int v = G[u][i];
        if(v != f)
        {
            fa[v][0] = u;
            deep [v] = deep[u] +1;
            ans[v] =deep[v]-1;
            dfs( v, u);
        }
    }
}
void init( int n)
{
    FOR(i, 1, 20)
    FOR(j, 1, n)
    fa[j][i] = fa[ fa[j][ i-1]][ i-1];
}
int lca(int u, int v)
{
    if(deep[u] < deep[v]) swap(u ,v);
    int d = deep[u] - deep[v];
    FOR(i, 0, 20 )
    if((1 << i) &d)
        u = fa[u][i];
    if(u == v) return  v;
    for(int i = 20 ; i>=0 ;i--)
    {
        if(fa[u][i]  != fa[v][i])
        {
            u = fa[u][i];
            v = fa[v][i];
        }
    }
    return fa[u] [0];
}

void bfs()
{
    queue<int>q;
    FOR(i, 0, red.size()-1)
    {
        int u =red[i];
        q.push(u);
        ans [u] =0;
    }
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        FOR(i, 0, G[u].size() -1)
        {
            int v = G[u][i];
            if(ans[v] > ans[u]+1 )
            {
                ans[v] = ans[u] +1;
                q.push( v);
            }
        }
    }
}
int main()
{
    int n, m;
    scanf( "%d%d" ,& n, &m);
    FOR(i, 1, n) G[i].clear();

    FOR(i, 1, n-1)
    {
        int u ,vv;
        scanf("%d%d" ,&u, &vv);
        G[u] . push_back(vv);
        G[vv] .push_back(u);
    }
    deep[1] = 1;
    ans[1] = 0;

    dfs(1 , 0);
    init(n);
    red.push_back(1);

    FOR(i, 1, m)
    {
        int op, x;
        scanf("%d%d" ,&op, &x);
        if(op == 1)
        {
            red.push_back(x);
            if(red.size() == 300){
                bfs();
                red.clear();
            }
        }
        else{
            if(red.size() >0)
            FOR(j, 0, red.size() -1)
            {
                ans[x] = min(ans[x] ,deep[x] + deep[red[j]]-2*deep[lca(x , red[j])]);
            }
            printf("%d\n", ans[x]);
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
#define FOR(i,j,k) for(int i =j; i<=k ;i++)
const int maxn = 100010;
int fa[maxn][22], deep[maxn], ans[maxn];
vector<int> G[maxn], red;
void dfs(int u, int f)
{
    deep[u] = deep[f]+1;
    ans[u] = deep[u] - 1;
    fa[u][0] = f;
    for(int i = 0; i < G[u].size(); i++)
        if(G[u][i] != f)  dfs(G[u][i], u);
}
void init(int n)
{
    for(int i = 1; i <= 20; i++)
        for(int u = 1; u <= n;u++)
            fa[u][i] = fa[fa[u][i-1]][i-1];
}
int lca(int x, int y)
{
    if(x == y) return x;
    if(deep[x] > deep[y]) swap(x, y);

    for(int i = 20; i >= 0; i--)
        if(deep[fa[y][i]] > deep[x]) y = fa[y][i];
    if(fa[y][0] == x) return x;

    if(deep[x] < deep[y] ) y = fa[y][0];

    for(int i = 20; i >= 0; i--)
        if(fa[x][i] != fa[y][i]) {
            x = fa[x][i];
            y = fa[y][i];
        }
    return fa[x][0];
}
void bfs()
{
    queue<int> ndq;
    for(int i = 0; i < red.size(); i++)
        ndq.push(red[i]), ans[red[i]] = 0;
    red.clear();
    int now;
    while(!ndq.empty())
    {
        now = ndq.front();
        ndq.pop();
        for(int i = 0; i < G[now].size(); i++)
            if(red[G[now][i]] > ans[now] + 1) {
                ans[G[now][i]] = ans[now] + 1;
                ndq.push( G[now][i] );
            }
    }
}
int main()
{
    int n, m;
    scanf( "%d%d" ,& n, &m);

    FOR(i, 1, n) G[i].clear();
    red.clear();
    memset(fa, 0, sizeof(fa));

    FOR(i, 1, n-1)
    {
        int u ,vv;
        scanf("%d%d" ,&u, &vv);
        G[u] . push_back(vv);
        G[vv] .push_back(u);
    }

    deep[0] = 0;

    dfs(1 , 0);
    init(n);

    FOR(i, 1, m)
    {
        int op, x;
        scanf("%d%d" ,&op, &x);
        if(op == 1)
        {

            red.push_back(x);
            if(red.size() == 300){
                bfs();
                //red.clear();
            }
        }
        else{
            //if(red.size() >=1){
                FOR(j, 0, red.size() -1)
                {
                    int anc = lca(ans[x] , red[i]);
                    ans[x] = min(ans[x] ,deep[x] + deep[red[j]] -2*deep[anc]);
                }
            //}
            printf("%d\n", ans[x]);
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
#define FOR(i,j,k) for(int i =j; i<=k ;i++)
const int maxn  =1e5+10;
vector<int>G[maxn];
vector<int>red;
int deep[maxn];
int md =22;
int fa[maxn][22];
void dfs(int u, int f)
{
    FOR(i, 0, G[u].size() -1)
    {
        int v = G[u][i];
        if(v != f)
        {
            fa[v][0] = u;
            deep [v] = deep[u] +1;
            dfs( v, u);
        }
    }
}
void init( int n)
{
    FOR(i, 1, md-1)
        FOR(j, 1, n)
            fa[j][i] = fa[ fa[j][ i-1]][ i-1];
}
int lca(int u, int v)
{
    if(deep[u] < deep[v]) swap(u ,v);
    int a = u,b= v;
    int d = deep[u] - deep[v];
    FOR(i, 0, md-1)
        if((1 << i) &d)
            u = fa[u][i];
    if(u == v) return  deep[a] - deep[v];
    for(int i = md -1 ; i>=0 ;i--)
    {
        if(fa[u][i]  != fa[v][i])
        {
            u = fa[u][i];
            v = fa[v][i];
        }
    }
    u = fa[u][0];

    return deep[a] - deep[u] + deep[b]-deep[u];
}
int ans[maxn];
void bfs()
{
    queue<int>q;
    FOR(i, 0, red.size()-1)
    {
        int u =red[i];
        q.push(u);
        ans [u] =0;
    }
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        FOR(i, 0, G[u].size() -1)
        {
            if(ans[G[u][i]] < ans[u]+1 )
            {
                ans[G[u][i]] = ans[u] +1;
                q.push( G[u][i]);
            }
        }
    }
}
int main()
{
    int n, m;
    scanf( "%d%d" ,& n, &m);
    FOR(i, 1, n-1)
    {
        int u ,vv;
        scanf("%d%d" ,&u, &vv);
        G[u] . push_back(vv);
        G[vv] .push_back(u);
    }
    deep[1] = 1;
    dfs(1 , -1);
    init(n);
    red.push_back(1);
    FOR(i, 1, n) ans[i] = n+2;
    ans[1] = 0;
    FOR(i, 1, m)
    {
        int op, x;
        scanf("%d%d" ,&op, &x);
        if(op == 1)
        {
            red.push_back(x);
            if(red.size() >= sqrt(n)){
                bfs();
                red.clear();
            }
        }
        else{
            FOR(i, 0, red.size() -1)
            {
                //cout<<x<<"asdf"<<red[i]<<endl;
                //cout<<ans[x] << " "<<lca(x, red[i])<<endl;
                ans[x] = min(ans[x] ,lca(x , red[i]));
            }
            printf("%d\n", ans[x]);
        }
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef unsigned long long int ULL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration

#define gu getchar
#define pu putchar
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)

#define DRT() int t; si(t); while(t--)

#define PlUSWRAP(index,n) index = (index+1)%n		//index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n 	//index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer

#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
const int N = int(1e5)+10;
const int LOGN = 20;
const int INF = int(1e9);
set<int> g[N];
int par[N],sub[N],level[N],ans[N];
int DP[LOGN][N];
int n,m;
/*Using centroid Decomposition of a tree */

/*----------- Pre-Processing ------------*/
void dfs0(int u)
{
	for(auto it=g[u].begin();it!=g[u].end();it++)
		if(*it!=DP[0][u])
		{
			DP[0][*it]=u;
			level[*it]=level[u]+1;
			dfs0(*it);
		}
}
void preprocess()
{
	level[0]=0;
	DP[0][0]=0;
	dfs0(0);
	for(int i=1;i<LOGN;i++)
		for(int j=0;j<n;j++)
			DP[i][j] = DP[i-1][DP[i-1][j]];
}
int lca(int a,int b)
{
	if(level[a]>level[b])swap(a,b);
	int d = level[b]-level[a];
	for(int i=0;i<LOGN;i++)
		if(d&(1<<i))
			b=DP[i][b];
	if(a==b)return a;
	for(int i=LOGN-1;i>=0;i--)
		if(DP[i][a]!=DP[i][b])
			a=DP[i][a],b=DP[i][b];
	return DP[0][a];
}
int dist(int u,int v)
{
	return level[u] + level[v] - 2*level[lca(u,v)];
}
/*-----------------Decomposition Part--------------------------*/
int nn;
void dfs1(int u,int p)
{
	sub[u]=1;
	nn++;
	for(auto it=g[u].begin();it!=g[u].end();it++)
		if(*it!=p)
		{
			dfs1(*it,u);
			sub[u]+=sub[*it];
		}
}
int dfs2(int u,int p)
{
	for(auto it=g[u].begin();it!=g[u].end();it++)
		if(*it!=p && sub[*it]>nn/2)
			return dfs2(*it,u);
	return u;
}
void decompose(int root,int p)
{
	nn=0;
	dfs1(root,root);
	int centroid = dfs2(root,root);
	if(p==-1)p=centroid;
	par[centroid]=p;
	for(auto it=g[centroid].begin();it!=g[centroid].end();it++)
	{
		g[*it].erase(centroid);
		decompose(*it,centroid);
	}
	g[centroid].clear();
}
/*----------------- Handle the Queries -----------------*/

void update(int u)
{
	int x = u;
	while(1)
	{
		ans[x] = min(ans[x],dist(x,u));
		if(x==par[x])
			break;
		x = par[x];
	}
}
int query(int u)
{
	int x = u;
	int ret=INF;
	while(1)
	{
		ret = min(ret,dist(u,x) + ans[x]);
		if(x==par[x])
			break;
		x = par[x];
	}
	return ret;
}
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=0;i<n-1;i++)
	{
		int u,v;
		scanf("%d %d",&u,&v);
		g[u-1].insert(v-1);
		g[v-1].insert(u-1);
	}
	preprocess();
	decompose(0,-1);
	for(int i=0;i<n;i++)
		ans[i]=INF;
	update(0);//first node is initially painted red
	while(m--)
	{
		int t,v;
		scanf("%d %d",&t,&v);v--;
		if(t==1)
			update(v);
		else
			dout(query(v));
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef complex<double> pnt;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> pp;
typedef double ld;
typedef long double lld;
#define INF 0x3f3f3f3f // for int
#define LL_INF 0x3f3f3f3f3f3f3f3f // for ll
#define ms(x, y) memset(x, y, sizeof(x))
//coordinate compression:sort(val.begin(), val.end());
//		val.resize(unique(val.begin(), val.end()) - val.begin());
#define nl '\n'
typedef unsigned long long ull;
const lld pi = 3.14159265358979323846;
const int MOD = 1e9 + 7;

//remember to remove ios stuff if i use scanf

//printf("%05lld\n", x); --> print last 5 digits including 0's
//printf("%02d:%02d", h, m); --> time
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll pwmd(ll b, ll exp) {
    ll ret = 1;
    while (exp > 0) {
        if (exp % 2 == 1) ret = (ret * b) % MOD;
        exp /= 2;
        b = (b * b) % MOD;
    }
    return ret;
}
//void RotateArr(int X) {
//    for (int n=0; n<X; n++) {
//        for (int i=0; i<N/2; i++) {
//            for (int j=0; j<N; j++) {
//                swap(a[i][j], a[N-i-1][j]);
//            }
//        }
//        for (int i=0; i<N; i++) {
//            for (int j=i+1; j<N; j++) {
//                swap(a[i][j], a[j][i]);
//            }
//        }
//    }
//}

/*
 * string input;
 *
 * stringstream ss(input);
 *- if the input contains '\n', separate lines with: string line; while (getline(ss, line))
 * - clear() to clear the stream
 * - >> : read smth from stringstream object ie. while (s >> word)
 */

struct pair_hash { //--> for unordered_set<pair<ll, ll>>
    //initialize the set with unordered_set<pair<ll, ll>, pair_hash>st
    inline std::size_t operator()(const std::pair<ll,ll> & v) const {
        return v.first*31+v.second;
    }
};
/* for dijkstra:
 * bool operator < (const E &other) const {
        return this->w > other.w;
    }
 */

const int MM = 1e5 + 5;
const int MX = 16;
int N, M, LCA[MM][MX+5], sz[MM], dep[MM], pre[MM], best[MM]; vector<vector<int>> adj; bool vis[MM];

int getCentroid(int v, int pa, int n) {
    for (int x : adj[v]) {
        if (x == pa || vis[x]) continue;
        if (sz[x] > n / 2) return getCentroid(x, v, n);
    }
    return v;
}

void init_centroid(int cur, int pa) {
    int siz = sz[cur];
    int c = getCentroid(cur, -1, siz);
    vis[c] = 1; pre[c] = pa;

    for (int x : adj[c]) {
        if (!vis[x]) {
            init_centroid(x, c);
        }
    }
}

void init() {
    for (int j = 1; j <= MX; j++) {
        for (int i = 1; i <= N; i++) {
            int par = LCA[i][j-1];
            if (par != -1) {
                LCA[i][j] = LCA[par][j-1];
            }
        }
    }
}

int lca(int a, int b) {
    if (dep[a] < dep[b]) swap(a, b); //dep[a] >= dep[b]
    int d = dep[a] - dep[b];
    while (d > 0) {
        int i = log2(d);
        a = LCA[a][i];
        d -= (1 << i);
    }
    if (a == b) return a;
    for (int i = MX; i >= 0; i--) {
        if (LCA[a][i] != -1 && LCA[b][i] != -1 && LCA[a][i] != LCA[b][i]) a = LCA[a][i], b = LCA[b][i];
    }
    return LCA[a][0];
}

void dfs0(int cur, int pa) {
    sz[cur] = 1; LCA[cur][0] = pa;
    for (int v : adj[cur]) {
        if (v != pa) {
            dep[v] = dep[cur] + 1;
            dfs0(v, cur);
            sz[cur] += sz[v];
        }
    }
}

int dist(int u, int v) {
    return dep[u] + dep[v] - 2 * dep[lca(u, v)];
}

void update(int u) {
    int x = u;
    while (x != -1) {
        best[x] = min(best[x], dist(x, u));
        x = pre[x];
    }
}

int query(int u) {
    int x = u, ret = INF;
    while (x != -1) {
        ret = min(ret, dist(u, x) + best[x]);
        x = pre[x];
    }
    return ret;
}

void solve(int tc) {

    cin >> N >> M; adj = vector<vector<int> >(N+1, vector<int>());
    for (int i = 1; i <= N; i++) { for (int j = 1; j <= MX; j++) LCA[i][j] = -1; }
    for (int i = 1; i <= N; i++) { best[i] = 2e5; pre[i] = -1; }
    for (int i = 1, a, b; i < N; i++) {
        cin >> a >> b;
        adj[a].push_back(b); adj[b].push_back(a);
    }
    dep[1] = 1; dfs0(1, -1); init(); init_centroid(1, -1);
    //1st node is red; update node 1
    update(1);
    while (M--) {
        int t, v; cin >> t >> v;
        if (t == 1) {
            update(v);
        } else if (t == 2) {
            cout << query(v) << nl;
        }
    }

}

//you should really read the stuff at the bottom

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int tc = 1; //cin >> tc;
    for (int t = 1; t <= tc; t++) solve(t);

    return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
// Did you read the bounds?
// Did you make typos?
// Are there edge cases (N=1?)
// Are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// Integer overflow?
// DS reset properly between test cases?
// Is using long longs causing TLE?
// Are you using floating points?
*/


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef complex<double> pnt;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> pp;
typedef double ld;
typedef long double lld;
#define INF 0x3f3f3f3f // for int
#define LL_INF 0x3f3f3f3f3f3f3f3f // for ll
#define ms(x, y) memset(x, y, sizeof(x))
//coordinate compression:sort(val.begin(), val.end());
//		val.resize(unique(val.begin(), val.end()) - val.begin());
#define nl '\n'
typedef unsigned long long ull;
const lld pi = 3.14159265358979323846;
const int MOD = 1e9 + 7;

//remember to remove ios stuff if i use scanf

//printf("%05lld\n", x); --> print last 5 digits including 0's
//printf("%02d:%02d", h, m); --> time
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll pwmd(ll b, ll exp) {
    ll ret = 1;
    while (exp > 0) {
        if (exp % 2 == 1) ret = (ret * b) % MOD;
        exp /= 2;
        b = (b * b) % MOD;
    }
    return ret;
}
//void RotateArr(int X) {
//    for (int n=0; n<X; n++) {
//        for (int i=0; i<N/2; i++) {
//            for (int j=0; j<N; j++) {
//                swap(a[i][j], a[N-i-1][j]);
//            }
//        }
//        for (int i=0; i<N; i++) {
//            for (int j=i+1; j<N; j++) {
//                swap(a[i][j], a[j][i]);
//            }
//        }
//    }
//}

/*
 * string input;
 *
 * stringstream ss(input);
 *- if the input contains '\n', separate lines with: string line; while (getline(ss, line))
 * - clear() to clear the stream
 * - >> : read smth from stringstream object ie. while (s >> word)
 */

struct pair_hash { //--> for unordered_set<pair<ll, ll>>
    //initialize the set with unordered_set<pair<ll, ll>, pair_hash>st
    inline std::size_t operator()(const std::pair<ll,ll> & v) const {
        return v.first*31+v.second;
    }
};
/* for dijkstra:
 * bool operator < (const E &other) const {
        return this->w > other.w;
    }
 */

const int MM = 1e5 + 5;
const int MX = 16;
int N, M, LCA[MM][MX+5], sz[MM], dep[MM], pre[MM], best[MM]; vector<vector<int>> adj; bool vis[MM];

int getCentroid(int v, int pa, int n) {
    for (int x : adj[v]) {
        if (x == pa || vis[x]) continue;
        if (sz[x] > n / 2) return getCentroid(x, v, n);
    }
    return v;
}

void init_centroid(int cur, int pa) {
    int siz = sz[cur];
    int c = getCentroid(cur, -1, siz);
    vis[c] = 1; pre[c] = pa;

    for (int x : adj[c]) {
        if (!vis[x]) {
            init_centroid(x, c);
        }
    }
}

//void init() {
//    for (int j = 1; j <= MX; j++) {
//        for (int i = 1; i <= N; i++) {
//            int par = LCA[i][j-1];
//            if (par != -1) {
//                LCA[i][j] = LCA[par][j-1];
//            }
//        }
//    }
//}
//
//int lca(int a, int b) {
//    if (dep[a] < dep[b]) swap(a, b); //dep[a] >= dep[b]
//    int d = dep[a] - dep[b];
//    while (d > 0) {
//        int i = log2(d);
//        a = LCA[a][i];
//        d -= (1 << i);
//    }
//    if (a == b) return a;
//    for (int i = MX; i >= 0; i--) {
//        if (LCA[a][i] != -1 && LCA[b][i] != -1 && LCA[a][i] != LCA[b][i]) a = LCA[a][i], b = LCA[b][i];
//    }
//    return LCA[a][0];
//}

void dfs(int v, int par) {
    LCA[v][0] = par;

    for (int i = 1; i <= MX; i++) {
        if (LCA[v][i - 1] == -1) LCA[v][i] = -1;
        else LCA[v][i] = LCA[LCA[v][i - 1]][i - 1];
    }

    for (int x: adj[v]) {
        if (x != par) {
            dep[x] = dep[v] + 1;
            dfs(x, v);
        }
    }
}

void init_lift(int v) {
    dep[v] = 0;
    dfs(v, -1);
}

int get(int v, int k) {
    for (int i = MX; i >= 0; i--) {
        if (v == -1) return v;
        if ((1 << i) <= k) {
            v = LCA[v][i];
            k -= (1 << i);
        }
    }
    return v;
}

int get_lca(int a, int b) {
    if (dep[a] < dep[b]) swap(a, b);
    int d = dep[a] - dep[b];
    int v = get(a, d);
    if (v == b) {
        return v;
    } else {
        for (int i = MX; i >= 0; i--) {
            if (LCA[v][i] != LCA[b][i]) {
                v = LCA[v][i];
                b = LCA[b][i];
            }
        }
        return LCA[b][0];
    }
}

void dfs0(int cur, int pa) {
    sz[cur] = 1; LCA[cur][0] = pa;
    for (int v : adj[cur]) {
        if (v != pa) {
            dep[v] = dep[cur] + 1;
            dfs0(v, cur);
            sz[cur] += sz[v];
        }
    }
}

int dist(int u, int v) {
    return dep[u] + dep[v] - 2 * dep[get_lca(u, v)];
}

void update(int u) {
    int x = u;
    while (x != -1) {
        best[x] = min(best[x], dist(x, u));
        x = pre[x];
    }
}

int query(int u) {
    int x = u, ret = INF;
    while (x != -1) {
        ret = min(ret, dist(u, x) + best[x]);
        x = pre[x];
    }
    return ret;
}

void solve(int tc) {

    cin >> N >> M; adj = vector<vector<int> >(N+1, vector<int>());
    for (int i = 1; i <= N; i++) { for (int j = 1; j <= MX; j++) LCA[i][j] = -1; }
    for (int i = 1; i <= N; i++) { best[i] = 2e5; pre[i] = -1; }
    for (int i = 1, a, b; i < N; i++) {
        cin >> a >> b;
        adj[a].push_back(b); adj[b].push_back(a);
    }
    dep[1] = 1; init_lift(1); init_centroid(1, -1);
    //1st node is red; update node 1
    update(1);
    while (M--) {
        int t, v; cin >> t >> v;
        if (t == 1) {
            update(v);
        } else if (t == 2) {
            cout << query(v) << nl;
        }
    }

}

//you should really read the stuff at the bottom

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int tc = 1; //cin >> tc;
    for (int t = 1; t <= tc; t++) solve(t);

    return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
// Did you read the bounds?
// Did you make typos?
// Are there edge cases (N=1?)
// Are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// Integer overflow?
// DS reset properly between test cases?
// Is using long longs causing TLE?
// Are you using floating points?
*/


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef complex<double> pnt;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> pp;
typedef double ld;
typedef long double lld;
#define INF 0x3f3f3f3f // for int
#define LL_INF 0x3f3f3f3f3f3f3f3f // for ll
#define ms(x, y) memset(x, y, sizeof(x))
//coordinate compression:sort(val.begin(), val.end());
//		val.resize(unique(val.begin(), val.end()) - val.begin());
#define nl '\n'
typedef unsigned long long ull;
const lld pi = 3.14159265358979323846;
const int MOD = 1e9 + 7;

//remember to remove ios stuff if i use scanf

//printf("%05lld\n", x); --> print last 5 digits including 0's
//printf("%02d:%02d", h, m); --> time
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll pwmd(ll b, ll exp) {
    ll ret = 1;
    while (exp > 0) {
        if (exp % 2 == 1) ret = (ret * b) % MOD;
        exp /= 2;
        b = (b * b) % MOD;
    }
    return ret;
}
//void RotateArr(int X) {
//    for (int n=0; n<X; n++) {
//        for (int i=0; i<N/2; i++) {
//            for (int j=0; j<N; j++) {
//                swap(a[i][j], a[N-i-1][j]);
//            }
//        }
//        for (int i=0; i<N; i++) {
//            for (int j=i+1; j<N; j++) {
//                swap(a[i][j], a[j][i]);
//            }
//        }
//    }
//}

/*
 * string input;
 *
 * stringstream ss(input);
 *- if the input contains '\n', separate lines with: string line; while (getline(ss, line))
 * - clear() to clear the stream
 * - >> : read smth from stringstream object ie. while (s >> word)
 */

struct pair_hash { //--> for unordered_set<pair<ll, ll>>
    //initialize the set with unordered_set<pair<ll, ll>, pair_hash>st
    inline std::size_t operator()(const std::pair<ll,ll> & v) const {
        return v.first*31+v.second;
    }
};
/* for dijkstra:
 * bool operator < (const E &other) const {
        return this->w > other.w;
    }
 */

const int MM = 1e5 + 5;
const int MX = 16;
int N, M, LCA[MM][MX+5], sz[MM], dep[MM], pre[MM], best[MM]; vector<vector<int>> adj; bool vis[MM];

int getCentroid(int v, int pa, int n) {
    for (int x : adj[v]) {
        if (x == pa || vis[x]) continue;
        if (sz[x] > n / 2) return getCentroid(x, v, n);
    }
    return v;
}

void init_centroid(int cur, int pa) {
    int siz = sz[cur];
    int c = getCentroid(cur, -1, siz);
    vis[c] = 1; pre[c] = pa;

    for (int x : adj[c]) {
        if (!vis[x]) {
            init_centroid(x, c);
        }
    }
}

void init() {
    for (int j = 1; j <= MX; j++) {
        for (int i = 1; i <= N; i++) {
            int par = LCA[i][j-1];
            if (par != -1) {
                LCA[i][j] = LCA[par][j-1];
            }
        }
    }
}

int lca(int a, int b) {
    if (dep[a] < dep[b]) swap(a, b); //dep[a] >= dep[b]
    int d = dep[a] - dep[b];
    while (d > 0) {
        int i = log2(d);
        a = LCA[a][i];
        d -= (1 << i);
    }
    if (a == b) return a;
    for (int i = MX; i >= 0; i--) {
        if (LCA[a][i] != -1 && LCA[b][i] != -1 && LCA[a][i] != LCA[b][i]) a = LCA[a][i], b = LCA[b][i];
    }
    return LCA[a][0];
}

void dfs0(int cur, int pa) {
    sz[cur] = 1; LCA[cur][0] = pa;
    for (int v : adj[cur]) {
        if (v != pa) {
            dep[v] = dep[cur] + 1;
            dfs0(v, cur);
            sz[cur] += sz[v];
        }
    }
}

void solve(int tc) {

    cin >> N >> M; adj = vector<vector<int> >(N+1, vector<int>());
    for (int i = 1; i <= N; i++) { for (int j = 1; j <= MX; j++) LCA[i][j] = -1; }
    for (int i = 1; i <= N; i++) { best[i] = 2e5; pre[i] = -1; }
    for (int i = 1, a, b; i < N; i++) {
        cin >> a >> b;
        adj[a].emplace_back(b); adj[b].emplace_back(a);
    }
    dep[1] = 1; dfs0(1, -1); init(); init_centroid(1, -1);
    //1st node is red; update node 1
    for (int i = 1; i != -1; i = pre[i]) {
        int ancestor = lca(1, i);
        if (ancestor == -1) continue;
        int d = dep[1] + dep[i] - 2 * dep[ancestor];
        best[i] = min(best[i], d);
    }
    while (M--) {
        int t, v; cin >> t >> v;
        if (t == 1) {
            //update
            for (int i = v; i != -1; i = pre[i]) {
                int ancestor = lca(v, i);
                if (ancestor == -1) continue;
                int d = dep[v] + dep[i] - 2 * dep[ancestor];
                best[i] = min(best[i], d);
            }
        } else if (t == 2) {
            //query
            int ans = INF;
            for (int i = v; i != -1; i = pre[i]) {
                int ancestor = lca(v, i);
                if (ancestor == -1) continue;
                int d = dep[v] + dep[i] - 2 * dep[ancestor];
                ans = min(ans, best[i] + d);
            }
            cout << ans << nl;
        }
    }

}

//you should really read the stuff at the bottom

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int tc = 1; //cin >> tc;
    for (int t = 1; t <= tc; t++) solve(t);

    return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
// Did you read the bounds?
// Did you make typos?
// Are there edge cases (N=1?)
// Are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// Integer overflow?
// DS reset properly between test cases?
// Is using long longs causing TLE?
// Are you using floating points?
*/


//why tle lol
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef complex<double> pnt;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> pp;
typedef double ld;
typedef long double lld;
#define INF 0x3f3f3f3f // for int
#define LL_INF 0x3f3f3f3f3f3f3f3f // for ll
#define ms(x, y) memset(x, y, sizeof(x))
//coordinate compression:sort(val.begin(), val.end());
//		val.resize(unique(val.begin(), val.end()) - val.begin());
#define nl '\n'
typedef unsigned long long ull;
const lld pi = 3.14159265358979323846;
const int MOD = 1e9 + 7;

//remember to remove ios stuff if i use scanf

//printf("%05lld\n", x); --> print last 5 digits including 0's
//printf("%02d:%02d", h, m); --> time
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll pwmd(ll b, ll exp) {
    ll ret = 1;
    while (exp > 0) {
        if (exp % 2 == 1) ret = (ret * b) % MOD;
        exp /= 2;
        b = (b * b) % MOD;
    }
    return ret;
}
//void RotateArr(int X) {
//    for (int n=0; n<X; n++) {
//        for (int i=0; i<N/2; i++) {
//            for (int j=0; j<N; j++) {
//                swap(a[i][j], a[N-i-1][j]);
//            }
//        }
//        for (int i=0; i<N; i++) {
//            for (int j=i+1; j<N; j++) {
//                swap(a[i][j], a[j][i]);
//            }
//        }
//    }
//}

/*
 * string input;
 *
 * stringstream ss(input);
 *- if the input contains '\n', separate lines with: string line; while (getline(ss, line))
 * - clear() to clear the stream
 * - >> : read smth from stringstream object ie. while (s >> word)
 */

struct pair_hash { //--> for unordered_set<pair<ll, ll>>
    //initialize the set with unordered_set<pair<ll, ll>, pair_hash>st
    inline std::size_t operator()(const std::pair<ll,ll> & v) const {
        return v.first*31+v.second;
    }
};
/* for dijkstra:
 * bool operator < (const E &other) const {
        return this->w > other.w;
    }
 */

const int MM = 1e5 + 5;
const int MX = 16;
int N, M, LCA[MM][MX+5], sz[MM], dep[MM], pre[MM], best[MM]; vector<vector<int>> adj; bool vis[MM];

void dfs(int x, int pa) {
    sz[x] = 1;
    for (int v : adj[x]) {
        if (!vis[v] && v != pa) {
            dfs(v, x);
            sz[x] += sz[v];
        }
    }
}

int getCentroid(int v, int pa, int n) {
    for (int x : adj[v]) {
        if (x == pa || vis[x]) continue;
        if (sz[x] > n / 2) return getCentroid(x, v, n);
    }
    return v;
}

void init_centroid(int cur, int pa) {
    dfs(cur, pa);
    int c = getCentroid(cur, -1, sz[cur]);
    vis[c] = 1; pre[c] = pa;

    for (int x : adj[c]) {
        if (!vis[x]) {
            init_centroid(x, c);
        }
    }
}

void init() {
    for (int j = 1; j <= MX; j++) {
        for (int i = 1; i <= N; i++) {
            int par = LCA[i][j-1];
            if (par != -1) {
                LCA[i][j] = LCA[par][j-1];
            }
        }
    }
}

int lca(int a, int b) {
    if (dep[a] < dep[b]) swap(a, b); //dep[a] >= dep[b]
    int d = dep[a] - dep[b];
    while (d > 0) {
        int i = log2(d);
        a = LCA[a][i];
        d -= (1 << i);
    }
    if (a == b) return a;
    for (int i = MX; i >= 0; i--) {
        if (LCA[a][i] != -1 && LCA[b][i] != -1 && LCA[a][i] != LCA[b][i]) a = LCA[a][i], b = LCA[b][i];
    }
    return LCA[a][0];
}

void dfs0(int cur, int pa) {
    LCA[cur][0] = pa;
    for (int v : adj[cur]) {
        if (v != pa) {
            dep[v] = dep[cur] + 1;
            dfs0(v, cur);
        }
    }
}

int dist(int u, int v) {
    return dep[u] + dep[v] - 2 * dep[lca(u, v)];
}

void update(int u) {
    int x = u;
    while (x != -1) {
        best[x] = min(best[x], dist(x, u));
        x = pre[x];
    }
}

int query(int u) {
    int x = u, ret = INF;
    while (x != -1) {
        ret = min(ret, dist(u, x) + best[x]);
        x = pre[x];
    }
    return ret;
}

void solve(int tc) {

    cin >> N >> M; adj = vector<vector<int> >(N+1, vector<int>());
    for (int i = 1; i <= N; i++) { for (int j = 1; j <= MX; j++) LCA[i][j] = -1; }
    for (int i = 1; i <= N; i++) { best[i] = 2e5; pre[i] = -1; }
    for (int i = 1, a, b; i < N; i++) {
        cin >> a >> b;
        adj[a].push_back(b); adj[b].push_back(a);
    }
    dep[1] = 1; dfs0(1, -1); init(); init_centroid(1, -1);
    //1st node is red; update node 1
    update(1);
    while (M--) {
        int t, v; cin >> t >> v;
        if (t == 1) {
            update(v);
        } else if (t == 2) {
            cout << query(v) << nl;
        }
    }

}

//you should really read the stuff at the bottom

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int tc = 1; //cin >> tc;
    for (int t = 1; t <= tc; t++) solve(t);

    return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
// Did you read the bounds?
// Did you make typos?
// Are there edge cases (N=1?)
// Are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// Integer overflow?
// DS reset properly between test cases?
// Is using long longs causing TLE?
// Are you using floating points?
*/


//why tle lol
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef complex<double> pnt;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> pp;
typedef double ld;
typedef long double lld;
#define INF 0x3f3f3f3f // for int
#define LL_INF 0x3f3f3f3f3f3f3f3f // for ll
#define ms(x, y) memset(x, y, sizeof(x))
//coordinate compression:sort(val.begin(), val.end());
//		val.resize(unique(val.begin(), val.end()) - val.begin());
#define nl '\n'
typedef unsigned long long ull;
const lld pi = 3.14159265358979323846;
const int MOD = 1e9 + 7;

//remember to remove ios stuff if i use scanf

//printf("%05lld\n", x); --> print last 5 digits including 0's
//printf("%02d:%02d", h, m); --> time
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll pwmd(ll b, ll exp) {
    ll ret = 1;
    while (exp > 0) {
        if (exp % 2 == 1) ret = (ret * b) % MOD;
        exp /= 2;
        b = (b * b) % MOD;
    }
    return ret;
}
//void RotateArr(int X) {
//    for (int n=0; n<X; n++) {
//        for (int i=0; i<N/2; i++) {
//            for (int j=0; j<N; j++) {
//                swap(a[i][j], a[N-i-1][j]);
//            }
//        }
//        for (int i=0; i<N; i++) {
//            for (int j=i+1; j<N; j++) {
//                swap(a[i][j], a[j][i]);
//            }
//        }
//    }
//}

/*
 * string input;
 *
 * stringstream ss(input);
 *- if the input contains '\n', separate lines with: string line; while (getline(ss, line))
 * - clear() to clear the stream
 * - >> : read smth from stringstream object ie. while (s >> word)
 */

struct pair_hash { //--> for unordered_set<pair<ll, ll>>
    //initialize the set with unordered_set<pair<ll, ll>, pair_hash>st
    inline std::size_t operator()(const std::pair<ll,ll> & v) const {
        return v.first*31+v.second;
    }
};
/* for dijkstra:
 * bool operator < (const E &other) const {
        return this->w > other.w;
    }
 */

const int MM = 1e5 + 5;
const int MX = 16;
int N, M, LCA[MM][MX+5], sz[MM], dep[MM], pre[MM], best[MM]; vector<vector<int>> adj; bool vis[MM];

int getCentroid(int v, int pa, int n) {
    for (int x : adj[v]) {
        if (x == pa || vis[x]) continue;
        if (sz[x] > n / 2) return getCentroid(x, v, n);
    }
    return v;
}

void init_centroid(int cur, int pa) {
    int siz = sz[cur];
    int c = getCentroid(cur, -1, siz);
    vis[c] = 1; pre[c] = pa;

    for (int x : adj[c]) {
        if (!vis[x]) {
            init_centroid(x, c);
        }
    }
}

void init() {
    for (int j = 1; j <= MX; j++) {
        for (int i = 1; i <= N; i++) {
            int par = LCA[i][j-1];
            if (par != -1) {
                LCA[i][j] = LCA[par][j-1];
            }
        }
    }
}

int lca(int a, int b) {
    if (dep[a] < dep[b]) swap(a, b); //dep[a] >= dep[b]
    int d = dep[a] - dep[b];
    while (d > 0) {
        int i = log2(d);
        a = LCA[a][i];
        d -= (1 << i);
    }
    if (a == b) return a;
    for (int i = MX; i >= 0; i--) {
        if (LCA[a][i] != -1 && LCA[b][i] != -1 && LCA[a][i] != LCA[b][i]) a = LCA[a][i], b = LCA[b][i];
    }
    return LCA[a][0];
}

void dfs0(int cur, int pa) {
    sz[cur] = 1; LCA[cur][0] = pa;
    for (int v : adj[cur]) {
        if (v != pa) {
            dep[v] = dep[cur] + 1;
            dfs0(v, cur);
            sz[cur] += sz[v];
        }
    }
}

int dist(int u, int v) {
    return dep[u] + dep[v] - 2 * dep[lca(u, v)];
}

void update(int u) {
    int x = u;
    while (x != -1) {
        best[x] = min(best[x], dist(x, u));
        x = pre[x];
    }
}

int query(int u) {
    int x = u, ret = INF;
    while (x != -1) {
        ret = min(ret, dist(u, x) + best[x]);
        x = pre[x];
    }
    return ret;
}

void solve(int tc) {

    cin >> N >> M; adj = vector<vector<int> >(N+1, vector<int>());
    for (int i = 1; i <= N; i++) { for (int j = 1; j <= MX; j++) LCA[i][j] = -1; }
    for (int i = 1; i <= N; i++) { best[i] = 2e5; pre[i] = -1; }
    for (int i = 1, a, b; i < N; i++) {
        cin >> a >> b;
        adj[a].push_back(b); adj[b].push_back(a);
    }
    dep[1] = 1; dfs0(1, -1); init(); init_centroid(1, -1);
    //1st node is red; update node 1
    update(1);
    while (M--) {
        int t, v; cin >> t >> v;
        if (t == 1) {
            update(v);
        } else if (t == 2) {
            cout << query(v) << nl;
        }
    }

}

//you should really read the stuff at the bottom

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int tc = 1; //cin >> tc;
    for (int t = 1; t <= tc; t++) solve(t);

    return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
// Did you read the bounds?
// Did you make typos?
// Are there edge cases (N=1?)
// Are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// Integer overflow?
// DS reset properly between test cases?
// Is using long longs causing TLE?
// Are you using floating points?
*/


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef complex<double> pnt;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> pp;
typedef double ld;
typedef long double lld;
#define INF 0x3f3f3f3f // for int
#define LL_INF 0x3f3f3f3f3f3f3f3f // for ll
#define ms(x, y) memset(x, y, sizeof(x))
//coordinate compression:sort(val.begin(), val.end());
//		val.resize(unique(val.begin(), val.end()) - val.begin());
#define nl '\n'
typedef unsigned long long ull;
const lld pi = 3.14159265358979323846;
const int MOD = 1e9 + 7;

//remember to remove ios stuff if i use scanf

//printf("%05lld\n", x); --> print last 5 digits including 0's
//printf("%02d:%02d", h, m); --> time
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll pwmd(ll b, ll exp) {
    ll ret = 1;
    while (exp > 0) {
        if (exp % 2 == 1) ret = (ret * b) % MOD;
        exp /= 2;
        b = (b * b) % MOD;
    }
    return ret;
}
//void RotateArr(int X) {
//    for (int n=0; n<X; n++) {
//        for (int i=0; i<N/2; i++) {
//            for (int j=0; j<N; j++) {
//                swap(a[i][j], a[N-i-1][j]);
//            }
//        }
//        for (int i=0; i<N; i++) {
//            for (int j=i+1; j<N; j++) {
//                swap(a[i][j], a[j][i]);
//            }
//        }
//    }
//}

/*
 * string input;
 *
 * stringstream ss(input);
 *- if the input contains '\n', separate lines with: string line; while (getline(ss, line))
 * - clear() to clear the stream
 * - >> : read smth from stringstream object ie. while (s >> word)
 */

struct pair_hash { //--> for unordered_set<pair<ll, ll>>
    //initialize the set with unordered_set<pair<ll, ll>, pair_hash>st
    inline std::size_t operator()(const std::pair<ll,ll> & v) const {
        return v.first*31+v.second;
    }
};
/* for dijkstra:
 * bool operator < (const E &other) const {
        return this->w > other.w;
    }
 */

const int MM = 1e5 + 5;
const int MX = 16;
int N, M, LCA[MM][MX+5], sz[MM], dep[MM], pre[MM], best[MM]; vector<int> adj[MM]; bool vis[MM];

int getCentroid(int v, int pa, int n) {
    for (int x : adj[v]) {
        if (x == pa || vis[x]) continue;
        if (sz[x] > n / 2) return getCentroid(x, v, n);
    }
    return v;
}

void init_centroid(int cur, int pa) {
    int siz = sz[cur];
    int c = getCentroid(cur, -1, siz);
    vis[c] = 1; pre[c] = pa;

    for (int x : adj[c]) {
        if (!vis[x]) {
            init_centroid(x, c);
        }
    }
}

void init() {
    for (int j = 1; j <= MX; j++) {
        for (int i = 1; i <= N; i++) {
            int par = LCA[i][j-1];
            if (par != -1) {
                LCA[i][j] = LCA[par][j-1];
            }
        }
    }
}

int lca(int a, int b) {
    if (dep[a] < dep[b]) swap(a, b); //dep[a] >= dep[b]
    int d = dep[a] - dep[b];
    while (d > 0) {
        int i = log2(d);
        a = LCA[a][i];
        d -= (1 << i);
    }
    if (a == b) return a;
    for (int i = MX; i >= 0; i--) {
        if (LCA[a][i] != -1 && LCA[b][i] != -1 && LCA[a][i] != LCA[b][i]) a = LCA[a][i], b = LCA[b][i];
    }
    return LCA[a][0];
}

void dfs0(int cur, int pa) {
    sz[cur] = 1; LCA[cur][0] = pa;
    for (int v : adj[cur]) {
        if (v != pa) {
            dep[v] = dep[cur] + 1;
            dfs0(v, cur);
            sz[cur] += sz[v];
        }
    }
}

void solve(int tc) {

    cin >> N >> M; ms(LCA, -1); ms(best, INF);
    for (int i = 1, a, b; i < N; i++) {
        cin >> a >> b;
        adj[a].push_back(b); adj[b].push_back(a);
    }
    dep[1] = 1; dfs0(1, -1); init(); init_centroid(1, -1);
    //1st node is red; update node 1
    for (int i = 1; i != -1; i = pre[i]) {
        int ancestor = lca(1, i);
        int d = dep[1] + dep[i] - 2 * dep[ancestor];
        best[i] = min(best[i], d);
    }
    while (M--) {
        int t, v; cin >> t >> v;
        if (t == 1) {
            //update
            for (int i = v; i != -1; i = pre[i]) {
                int ancestor = lca(v, i);
                int d = dep[v] + dep[i] - 2 * dep[ancestor];
                best[i] = min(best[i], d);
            }
        } else if (t == 2) {
            //query
            int ans = INF;
            for (int i = v; i != -1; i = pre[i]) {
                int ancestor = lca(v, i);
                int d = dep[v] + dep[i] - 2 * dep[ancestor];
                ans = min(ans, best[i] + d);
            }
            cout << ans << nl;
        }
    }

}

//you should really read the stuff at the bottom

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int tc = 1; //cin >> tc;
    for (int t = 1; t <= tc; t++) solve(t);

    return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
// Did you read the bounds?
// Did you make typos?
// Are there edge cases (N=1?)
// Are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// Integer overflow?
// DS reset properly between test cases?
// Is using long longs causing TLE?
// Are you using floating points?
*/


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef complex<double> pnt;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> pp;
typedef double ld;
typedef long double lld;
#define INF 0x3f3f3f3f // for int
#define LL_INF 0x3f3f3f3f3f3f3f3f // for ll
#define ms(x, y) memset(x, y, sizeof(x))
//coordinate compression:sort(val.begin(), val.end());
//		val.resize(unique(val.begin(), val.end()) - val.begin());
#define nl '\n'
typedef unsigned long long ull;
const lld pi = 3.14159265358979323846;
const int MOD = 1e9 + 7;

//remember to remove ios stuff if i use scanf

//printf("%05lld\n", x); --> print last 5 digits including 0's
//printf("%02d:%02d", h, m); --> time
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll pwmd(ll b, ll exp) {
    ll ret = 1;
    while (exp > 0) {
        if (exp % 2 == 1) ret = (ret * b) % MOD;
        exp /= 2;
        b = (b * b) % MOD;
    }
    return ret;
}
//void RotateArr(int X) {
//    for (int n=0; n<X; n++) {
//        for (int i=0; i<N/2; i++) {
//            for (int j=0; j<N; j++) {
//                swap(a[i][j], a[N-i-1][j]);
//            }
//        }
//        for (int i=0; i<N; i++) {
//            for (int j=i+1; j<N; j++) {
//                swap(a[i][j], a[j][i]);
//            }
//        }
//    }
//}

/*
 * string input;
 *
 * stringstream ss(input);
 *- if the input contains '\n', separate lines with: string line; while (getline(ss, line))
 * - clear() to clear the stream
 * - >> : read smth from stringstream object ie. while (s >> word)
 */

struct pair_hash { //--> for unordered_set<pair<ll, ll>>
    //initialize the set with unordered_set<pair<ll, ll>, pair_hash>st
    inline std::size_t operator()(const std::pair<ll,ll> & v) const {
        return v.first*31+v.second;
    }
};
/* for dijkstra:
 * bool operator < (const E &other) const {
        return this->w > other.w;
    }
 */

const int MM = 1e5 + 5;
const int MX = 16;
int N, M, LCA[MM][MX+5], sz[MM], dep[MM], pre[MM], best[MM]; vector<vector<int>> adj; bool vis[MM];

//int getCentroid(int v, int pa, int n) {
//    for (int x : adj[v]) {
//        if (x == pa || vis[x]) continue;
//        if (sz[x] > n / 2) return getCentroid(x, v, n);
//    }
//    return v;
//}
//
//void init_centroid(int cur, int pa) {
//    int siz = sz[cur];
//    int c = getCentroid(cur, -1, siz);
//    vis[c] = 1; pre[c] = pa;
//
//    for (int x : adj[c]) {
//        if (!vis[x]) {
//            init_centroid(x, c);
//        }
//    }
//}

int find_centroid(int v, int p, int n) {
    for (int x: adj[v]) {
        if (x != p) {
            if (!vis[x] && sz[x] > n / 2) {
                return find_centroid(x, v, n);
            }
        }
    }

    return v;
}

void init_centroid(int v = 1, int p = -1) {
    int c = find_centroid(v, -1, sz[v]);
    vis[c] = true;
    pre[c] = p;

    for (int x: adj[c]) {
        if (!vis[x]) {
            init_centroid(x, c);
        }
    }
}

void init() {
    for (int j = 1; j <= MX; j++) {
        for (int i = 1; i <= N; i++) {
            int par = LCA[i][j-1];
            if (par != -1) {
                LCA[i][j] = LCA[par][j-1];
            }
        }
    }
}

int lca(int a, int b) {
    if (dep[a] < dep[b]) swap(a, b); //dep[a] >= dep[b]
    int d = dep[a] - dep[b];
    while (d > 0) {
        int i = log2(d);
        a = LCA[a][i];
        d -= (1 << i);
    }
    if (a == b) return a;
    for (int i = MX; i >= 0; i--) {
        if (LCA[a][i] != -1 && LCA[b][i] != -1 && LCA[a][i] != LCA[b][i]) a = LCA[a][i], b = LCA[b][i];
    }
    return LCA[a][0];
}

void dfs0(int cur, int pa) {
    sz[cur] = 1; LCA[cur][0] = pa;
    for (int v : adj[cur]) {
        if (v != pa) {
            dep[v] = dep[cur] + 1;
            dfs0(v, cur);
            sz[cur] += sz[v];
        }
    }
}

int dist(int u, int v) {
    return dep[u] + dep[v] - 2 * dep[lca(u, v)];
}

void update(int u) {
    int x = u;
    while (x != -1) {
        best[x] = min(best[x], dist(x, u));
        x = pre[x];
    }
}

int query(int u) {
    int x = u, ret = INF;
    while (x != -1) {
        ret = min(ret, dist(u, x) + best[x]);
        x = pre[x];
    }
    return ret;
}

void solve(int tc) {

    cin >> N >> M; adj = vector<vector<int> >(N+1, vector<int>());
    for (int i = 1; i <= N; i++) { for (int j = 1; j <= MX; j++) LCA[i][j] = -1; }
    for (int i = 1; i <= N; i++) { best[i] = 2e5; pre[i] = -1; }
    for (int i = 1, a, b; i < N; i++) {
        cin >> a >> b;
        adj[a].push_back(b); adj[b].push_back(a);
    }
    dep[1] = 1; dfs0(1, -1); init(); init_centroid(1, -1);
    //1st node is red; update node 1
    update(1);
    while (M--) {
        int t, v; cin >> t >> v;
        if (t == 1) {
            update(v);
        } else if (t == 2) {
            cout << query(v) << nl;
        }
    }

}

//you should really read the stuff at the bottom

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int tc = 1; //cin >> tc;
    for (int t = 1; t <= tc; t++) solve(t);

    return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
// Did you read the bounds?
// Did you make typos?
// Are there edge cases (N=1?)
// Are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// Integer overflow?
// DS reset properly between test cases?
// Is using long longs causing TLE?
// Are you using floating points?
*/


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef complex<double> pnt;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> pp;
typedef double ld;
typedef long double lld;
#define INF 0x3f3f3f3f // for int
#define LL_INF 0x3f3f3f3f3f3f3f3f // for ll
#define ms(x, y) memset(x, y, sizeof(x))
//coordinate compression:sort(val.begin(), val.end());
//		val.resize(unique(val.begin(), val.end()) - val.begin());
#define nl '\n'
typedef unsigned long long ull;
const lld pi = 3.14159265358979323846;
const int MOD = 1e9 + 7;

//remember to remove ios stuff if i use scanf

//printf("%05lld\n", x); --> print last 5 digits including 0's
//printf("%02d:%02d", h, m); --> time
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll pwmd(ll b, ll exp) {
    ll ret = 1;
    while (exp > 0) {
        if (exp % 2 == 1) ret = (ret * b) % MOD;
        exp /= 2;
        b = (b * b) % MOD;
    }
    return ret;
}
//void RotateArr(int X) {
//    for (int n=0; n<X; n++) {
//        for (int i=0; i<N/2; i++) {
//            for (int j=0; j<N; j++) {
//                swap(a[i][j], a[N-i-1][j]);
//            }
//        }
//        for (int i=0; i<N; i++) {
//            for (int j=i+1; j<N; j++) {
//                swap(a[i][j], a[j][i]);
//            }
//        }
//    }
//}

/*
 * string input;
 *
 * stringstream ss(input);
 *- if the input contains '\n', separate lines with: string line; while (getline(ss, line))
 * - clear() to clear the stream
 * - >> : read smth from stringstream object ie. while (s >> word)
 */

struct pair_hash { //--> for unordered_set<pair<ll, ll>>
    //initialize the set with unordered_set<pair<ll, ll>, pair_hash>st
    inline std::size_t operator()(const std::pair<ll,ll> & v) const {
        return v.first*31+v.second;
    }
};
/* for dijkstra:
 * bool operator < (const E &other) const {
        return this->w > other.w;
    }
 */

const int MM = 1e5 + 5;
const int MX = 16;
int N, M, LCA[MM][MX+5], sz[MM], dep[MM], pre[MM], best[MM]; vector<int> adj[MM]; bool vis[MM];

int getCentroid(int v, int pa, int n) {
    for (int x : adj[v]) {
        if (x == pa || vis[x]) continue;
        if (sz[x] > n / 2) return getCentroid(x, v, n);
    }
    return v;
}

void init_centroid(int cur, int pa) {
    int siz = sz[cur];
    int c = getCentroid(cur, -1, siz);
    vis[c] = 1; pre[c] = pa;

    for (int x : adj[c]) {
        if (!vis[x]) {
            init_centroid(x, c);
        }
    }
}

void init() {
    for (int j = 1; j <= MX; j++) {
        for (int i = 1; i <= N; i++) {
            int par = LCA[i][j-1];
            if (par != -1) {
                LCA[i][j] = LCA[par][j-1];
            }
        }
    }
}

int lca(int a, int b) {
    if (dep[a] < dep[b]) swap(a, b); //dep[a] >= dep[b]
    int d = dep[a] - dep[b];
    while (d > 0) {
        int i = log2(d);
        a = LCA[a][i];
        d -= (1 << i);
    }
    if (a == b) return a;
    for (int i = MX; i >= 0; i--) {
        if (LCA[a][i] != -1 && LCA[b][i] != -1 && LCA[a][i] != LCA[b][i]) a = LCA[a][i], b = LCA[b][i];
    }
    return LCA[a][0];
}

void dfs0(int cur, int pa) {
    sz[cur] = 1; LCA[cur][0] = pa;
    for (int v : adj[cur]) {
        if (v != pa) {
            dep[v] = dep[cur] + 1;
            dfs0(v, cur);
            sz[cur] += sz[v];
        }
    }
}

void solve(int tc) {

    cin >> N >> M; ms(LCA, -1); ms(best, INF);
    for (int i = 1, a, b; i < N; i++) {
        cin >> a >> b;
        adj[a].push_back(b); adj[b].push_back(a);
    }
    dep[1] = 1; dfs0(1, -1); init(); init_centroid(1, -1);
    //1st node is red; update node 1
    for (int i = 1; i != -1; i = pre[i]) {
        int ancestor = lca(1, i);
        if (ancestor == -1) continue;
        int d = dep[1] + dep[i] - 2 * dep[ancestor];
        best[i] = min(best[i], d);
    }
    while (M--) {
        int t, v; cin >> t >> v;
        if (t == 1) {
            //update
            for (int i = v; i != -1; i = pre[i]) {
                int ancestor = lca(v, i);
                if (ancestor == -1) continue;
                int d = dep[v] + dep[i] - 2 * dep[ancestor];
                best[i] = min(best[i], d);
            }
        } else if (t == 2) {
            //query
            int ans = INF;
            for (int i = v; i != -1; i = pre[i]) {
                int ancestor = lca(v, i);
                if (ancestor == -1) continue;
                int d = dep[v] + dep[i] - 2 * dep[ancestor];
                ans = min(ans, best[i] + d);
            }
            cout << ans << nl;
        }
    }

}

//you should really read the stuff at the bottom

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int tc = 1; //cin >> tc;
    for (int t = 1; t <= tc; t++) solve(t);

    return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
// Did you read the bounds?
// Did you make typos?
// Are there edge cases (N=1?)
// Are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// Integer overflow?
// DS reset properly between test cases?
// Is using long longs causing TLE?
// Are you using floating points?
*/