// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

const ll inf = 5e15;
ll N;
VV<ll> edges;
V<bool> black;

bool is_black(ll n) { return black[n]; }

template <typename T>
class SegmentTree {
public:
    ll size;
    vector<T> node;
    function<T(T, T)> comp;
    T identity_ele;  //comp(x, identity_ele) == x

    SegmentTree(const vector<T> &v, function<T(T, T)> comp, T identity_ele) 
        : comp(comp),
          identity_ele(identity_ele)
    {
        ll tmp = 1;
        while(tmp < v.size()) tmp = (tmp << 1);
        this->size = tmp;
        this->identity_ele = identity_ele;
        this->comp = comp;
        node = V<T>(2 * size - 1, identity_ele);
        for(ll i = 0; i < v.size(); i++) {
            node[i + size - 1] = v[i];
        }
        for(ll i = size - 2; 0 <= i; i--) {
            node[i] = comp(node[i * 2 + 1], node[i * 2 + 2]);
        }
    }

    void update(ll pos, T value) {
        pos += size - 1;
        node[pos] = value;
        while(pos > 0) {
            pos = (pos - 1) / 2;
            node[pos] = comp(node[2 * pos + 1], node[2 * pos + 2]);
        }
    }

    T query(ll a, ll b) {
        return sub_query(a, b, 0, 0, size);
    }

    T sub_query(ll a, ll b, ll k, ll l, ll r) {
        if(r <= a || b <= l) {
            return identity_ele;
        } else if(a <= l && r <= b) {
            return node[k];
        } else {
            T left = sub_query(a, b, k * 2 + 1, l, (l + r) / 2);
            T right = sub_query(a, b, k * 2 + 2, (l + r) / 2, r);
            return comp(left, right);
        }
    }
};

template <typename T, typename L>
class LazySegmentTree {
private:
    using Merge = function<T(T, T)>;
    using Apply = function<T(T, L)>;
    using Update = function<L(L, L)>;
    using CalcLazyValue = function<L(ssize_t, ssize_t, L)>;
    using Prop = function<L(L)>;

    size_t arr_size;
    T init_node;
    L init_lazy;
    vector<T> node;
    vector<L> lazy;
    vector<bool> lazy_flag;
    Merge merge_node;
    Apply apply_lazy_value;
    Update update_lazy_value;
    CalcLazyValue calc_lazy_value;
    Prop prop_lazy_value;
    
public:
    LazySegmentTree(vector<T> v, 
                    T init_node,
                    L init_lazy, 
                    Merge merge_node,
                    Apply apply_lazy_value,
                    Update update_lazy_value,
                    CalcLazyValue calc_lazy_value,
                    Prop prop_lazy_value = [](L l) { return l; })
        : init_node(init_node),
          init_lazy(init_lazy),
          merge_node(merge_node),
          apply_lazy_value(apply_lazy_value),
          update_lazy_value(update_lazy_value),
          calc_lazy_value(calc_lazy_value),
          prop_lazy_value(prop_lazy_value)
    {
        {
            arr_size = 1;
            while(arr_size < v.size()) arr_size *= 2;
        }
        node.resize(2 * arr_size - 1, init_node);
        lazy.resize(2 * arr_size - 1, init_lazy);
        lazy_flag.resize(2 * arr_size - 1, false);
        for(ll i = 0; i < v.size(); i++) node[i + arr_size - 1] = v[i];
        for(ll i = arr_size - 2; 0 <= i; i--) node[i] = merge_node(node[i * 2 + 1], node[i * 2 + 2]);
    }

    void lazy_eval(ll pos, ll left, ll right) {
        if(!lazy_flag[pos]) return;

        node[pos] = apply_lazy_value(node[pos], lazy[pos]);
        lazy_flag[pos] = false;

        if(right - left > 1) {
            for(ll idx = 2 * pos + 1; idx <= 2 * pos + 2; idx++) {
                lazy[idx] = update_lazy_value(lazy[idx], prop_lazy_value(lazy[pos]));
                lazy_flag[idx] = true;
            }
        }

        lazy[pos] = init_lazy;
    }

    void update_query(ll left, ll right, L val, ll pos = 0, ll node_left = 0, ll node_right = -1) {
        if(node_right < 0) node_right = arr_size;

        lazy_eval(pos, node_left, node_right);

        if(right <= node_left || node_right <= left) return;
        
        if(left <= node_left && node_right <= right) {
            lazy[pos] = calc_lazy_value(node_left, node_right, val);
            lazy_flag[pos] = true;
            lazy_eval(pos, node_left, node_right);
        } else {
            ll mid = (node_left + node_right) / 2;
            update_query(left, right, val, 2 * pos + 1, node_left, mid);
            update_query(left, right, val, 2 * pos + 2, mid, node_right);
            node[pos] = merge_node(node[2 * pos + 1], node[2 * pos + 2]);
        }
    }

    T get_query(ll left, ll right, ll pos = 0, ll node_left = 0, ll node_right = -1) {
        if(node_right < 0) node_right = arr_size;
        
        lazy_eval(pos, node_left, node_right);

        if(node_right <= left || right <= node_left) return init_node;
        if(left <= node_left && node_right <= right) return node[pos];

        ll mid = (node_left + node_right) / 2;
        return merge_node(get_query(left, right, 2 * pos + 1, node_left, mid),
                          get_query(left, right, 2 * pos + 2, mid, node_right));
    }
};

struct HLD {
    V<ll> p_node, head_node, hld_id, heavy , tree_size;
    HLD(const VV<ll> &edges) : p_node(edges.size()), head_node(edges.size()),
                               hld_id(edges.size()), heavy(edges.size(), -1), 
                               tree_size(edges.size())
    {
        calc_size(0, -1, edges);
        ll id = 0;
        calc_id(0, -1, edges, id);
    }

    ll calc_size(ll cur, ll pre, const VV<ll> &edges) {
        ll ret = 1;
        p_node[cur] = pre;
        for(ll nxt : edges[cur]) if(nxt != pre) {
            ret += calc_size(nxt, cur, edges);
            if(heavy[cur] == -1 || 
               tree_size[heavy[cur]] < tree_size[nxt]) {
                heavy[cur] = nxt;
            }
        }
        return tree_size[cur] = ret;
    }

    void calc_id(ll cur, ll pre, const VV<ll> &edges, ll &id) {
        if(cur == -1) return;
        hld_id[cur] = id++;
        if(pre == -1) head_node[cur] = cur;
        else head_node[cur] = (heavy[pre] == cur ? head_node[pre] : cur);
        if(cur != heavy[cur]) calc_id(heavy[cur], cur, edges, id);
        for(ll nxt : edges[cur]) {
            if(nxt == pre || nxt == heavy[cur]) continue;
            calc_id(nxt, cur, edges, id);
        }
    }

    ll head_id(ll node) { return hld_id[head_node[node]]; }

    ll lca(ll n1, ll n2) {
        while(true) {
            if(hld_id[n2] < hld_id[n1]) swap(n1, n2);
            if(head_node[n1] == head_node[n2]) break;
            n2 = p_node[head_node[n2]];
        }
        return n1;
    }

    void query1(ll n, ll val, SegmentTree<ll> &black_seg, LazySegmentTree<ll, ll> &cnt_seg) {
        n = p_node[n];
        while(true) {
            if(n == -1) break;
            ll id = hld_id[n];
            ll hid = head_id(n);
            ll black = black_seg.query(hid, id + 1);
            if(black == -inf) {
                cnt_seg.update_query(hid, id + 1, val);
            } else {
                cnt_seg.update_query(black, id + 1, val);
                break;
            }
            n = p_node[head_node[n]];
        }
    }

    ll query2(ll n, SegmentTree<ll> &black_seg, LazySegmentTree<ll, ll> &cnt_seg) {
        ll qid;
        while(true) {
            ll id = hld_id[n];
            ll hid = head_id(n);
            ll black = black_seg.query(hid, id + 1);
            if(black != -inf) {
                qid = black + 1;
                break;
            }
            ll pn = p_node[head_node[n]];
            if(pn == -1) {
                qid = hid;
                break;
            }
            if(is_black(pn)) {
                qid = hid;
                break;
            }
            n = pn;
        }
        return cnt_seg.get_query(qid, qid + 1);
    }
};

int main() {
    ll Q;
    cin >> N >> Q;
    edges.resize(N);
    black.resize(N);
    for(ll i = 1; i < N; i++) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    HLD hld(edges);
    SegmentTree<ll> black_seg(V<ll>(N, -inf), [](ll a, ll b) { return max(a, b); }, -inf);
    V<ll> init_v(N);
    for(ll i = 0; i < N; i++) init_v[hld.hld_id[i]] = hld.tree_size[i];
    LazySegmentTree<ll, ll> cnt_seg(init_v, 0, 0,
                                    [&](ll a, ll b) { return a + b; },
                                    [&](ll a, ll b) { return a + b; },
                                    [&](ll a, ll b) { return a + b; },
                                    [&](ll l, ll r, ll v) { return (r - l) * v; },
                                    [&](ll a) { return a / 2; });

    DEBUG(hld.tree_size);

    while(Q--) {
        ll t, v;
        cin >> t >> v;
        v--;
        if(t == 1) {
            ll id = hld.hld_id[v];
            ll val = cnt_seg.get_query(id, id + 1);
            DEBUG(val);
            if(is_black(v)) {
                black[v] = false;
                black_seg.update(id, -inf);
                hld.query1(v, val, black_seg, cnt_seg);
            } else {
                black[v] = true;
                black_seg.update(id, id);
                hld.query1(v, -val, black_seg, cnt_seg);
            }
        } else {
            cout << hld.query2(v, black_seg, cnt_seg) << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 36488