#include <stdio.h>
#include <utility>
#include <iostream>

struct Node;
extern Node *NONE;
struct Node {
#define l ch[0]
#define r ch[1]
	Node *p = NONE;
	Node *ch[2] = {NONE, NONE};
	bool rev = false;
	bool enabled_self = false;
	int disabled_sum = 0;
	int light = 0; // LIGHT
	int right = 0;
	int left = 0;
	Node *fetch() {
		if (l != NONE) l->flush();
		if (r != NONE) r->flush();
		disabled_sum = l->disabled_sum + r->disabled_sum + !enabled_self;
		if (enabled_self) {
			left = l->disabled_sum ? l->left : light + l->left + 1 + r->left;
			right = r->disabled_sum ? r->right : light + r->right + 1 + l->right;
		} else left = l->left, right = r->right;
		return this;
	}
	Node *flush() {
		if (rev) {
			std::swap(l, r);
			l->rev ^= 1;
			r->rev ^= 1;
			std::swap(left, right);
			rev = false;
		}
		return this;
	}
	bool is_root() { return p == NONE || (p->l != this && p->r != this); }
	Node *rotate(bool dir) {
		Node *new_root = ch[!dir];
		ch[!dir] = new_root->ch[dir];
		ch[!dir]->p = this;
		new_root->ch[dir] = this;
		if (p->l == this) p->l = new_root;
		if (p->r == this) p->r = new_root;
		new_root->p = p;
		p = new_root;
		return fetch(), new_root->fetch();
	}
	void splay() {
		flush();
		while (!is_root()) {
			if (p->is_root()) {
				p->flush(), flush();
				p->rotate(p->l == this);
			} else {
				Node *pp = p->p;
				pp->flush(), p->flush(), flush();
				bool flag0 = pp->l == p;
				bool flag1 = p->l == this;
				if (flag0 == flag1) pp->rotate(flag0);
				p->rotate(flag1);
				if (flag0 != flag1) pp->rotate(flag0);
			}
		}
	}
	Node *expose() {
		Node *prev = NONE;
		for (Node *cur = this; cur != NONE; cur = cur->p) {
			cur->splay();
			if (cur->r != NONE) {
				cur->r->flush();
				cur->light += cur->r->left;
			}
			cur->r = prev;
			if (cur->r != NONE) {
				cur->r->flush();
				cur->light -= cur->r->left;
			}
			cur->fetch();
			prev = cur;
		}
		splay();
		return prev;
	}
	void link(Node *parent) {
		expose();
		parent->expose();
		p = parent;
		parent->r = this;
		parent->fetch();
	}
	void cut() {
		expose();
		l->p = NONE;
		l = NONE;
		fetch();
	}
	void evert() {
		expose();
		rev ^= 1;
		flush();
	}
#undef l
#undef r
};
Node *NONE = new Node;

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int q = ri();
	Node nodes[n];
	for (auto &i : nodes) i.enabled_self = true, i.fetch();
	
	for (int i = 1; i < n; i++) {
		int a = ri() - 1;
		int b = ri() - 1;
		nodes[a].evert();
		nodes[a].link(nodes + b);
	}
	for (int i = 0; i < q; i++) {
		int t = ri();
		int x = ri() - 1;
		if (t == 1) nodes[x].expose(), nodes[x].enabled_self ^= 1, nodes[x].fetch();
		else nodes[x].evert(), printf("%d\n", nodes[x].left);
	}
	
	return 0;
}

