#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+9;
int n,m,op,x,y,dep,nQ,tI[N],tO[N],timer,id[N],d[N],son[N],sz[N],ans[N],bit[N];
vector<int> to[N];
typedef struct {int id,d;} Query;
vector<Query> q[N];
void dfs_son(int u, int fa)
{
id[tI[u] = ++timer] = u;
d[u] = d[fa] + 1;
sz[u] = 1;
for (auto v : to[u])
{
if (v == fa) continue;
dfs_son(v, u);
if (sz[v] > sz[son[u]]) son[u] = v;
sz[u] += sz[v];
}
tO[u] = timer;
}
int LSB(int x) {return x & -x;}
void add(int x, int z)
{
while (x <= n)
{
bit[x] += z;
x += LSB(x);
}
}
int psq(int x)
{
int ret = 0;
while (x)
{
ret += bit[x];
x -= LSB(x);
}
return ret;
}
void aNode(int u) {add(d[u], 1);}
void aTree(int u) {for (int i = tI[u]; i <= tO[u]; ++i) aNode(id[i]);}
void cTree(int u) {for (int i = tI[u]; i <= tO[u]; ++i) add(d[id[i]], -1);}
void dfs(int u, int fa, bool hvy)
{
for (auto v : to[u]) if (v != fa && v != son[u]) dfs(v, u, 0);
if (son[u]) dfs(son[u], u, 1);
for (auto v : to[u]) if (v != fa && v != son[u]) aTree(v);
aNode(u);
for (int i = 0; i < q[u].size(); ++i)
ans[q[u][i].id] = psq(n) - psq(q[u][i].d - 1);
if (!hvy) cTree(u);
}
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i < n; ++i)
{
scanf("%d%d", &x, &y);
to[x].push_back(y);
to[y].push_back(x);
}
while (m--)
{
scanf("%d%d", &op, &x);
if (op == 1) dep = x;
else q[x].push_back((Query){++nQ, dep});
}
dfs_son(1, 0);
dfs(1, 0, 1);
for (int i = 1; i <= nQ; ++i) printf("%d\n", ans[i]);
return 0;
}