import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.ArrayList;
public class WaterTree {
in.nextToken();
return (int) in.nval;
}
static final int MAXN = 500005;
static ArrayList<ArrayList<Integer>> G;
static int timer;
static int[] tin = new int[MAXN];
static int[] tout = new int[MAXN];
static int[] parent = new int[MAXN];
static void dfs(int u, int p) {
parent[u] = p;
tin[u] = timer;
for (int v : G.get(u)) {
if (v != p) {
dfs(v, u);
}
}
tout[u] = timer++;
}
static boolean[] T = new boolean[8 * MAXN];
static boolean[] promise = new boolean[8 * MAXN];
static void build(int v, int tl, int tr) {
if (tl < tr) {
int tm = (tl + tr) / 2;
build(2 * v, tl, tm);
build(2 * v + 1, tm + 1, tr);
}
T[v] = true;
}
static void push(int v) {
if (promise[v]) {
promise[v] = false;
promise[2 * v] = promise[2 * v + 1] = true;
T[2 * v] = T[2 * v + 1] = false;
}
}
static boolean get(int l, int r, int v, int tl, int tr) {
if (l > r) {
return false;
}
push(v);
if (tl == l && tr == r) {
return T[v];
} else {
int tm = (tl + tr) / 2;
return get
(l,
Math.
min(r, tm
),
2 * v, tl, tm
) || get
(Math.
max(l, tm
+ 1), r,
2 * v
+ 1, tm
+ 1, tr
); }
}
static void update(int p, int v, int tl, int tr) {
push(v);
T[v] = true;
if (tl < tr) {
int tm = (tl + tr) / 2;
if (p <= tm) {
update(p, 2 * v, tl, tm);
} else {
update(p, 2 * v + 1, tm + 1, tr);
}
}
}
static void color(int l, int r, int v, int tl, int tr) {
if (l > r || promise[v]) {
return;
}
if (l == tl && r == tr) {
promise[v] = true;
T[v] = false;
} else {
int tm = (tl + tr) / 2;
color
(l,
Math.
min(r, tm
),
2 * v, tl, tm
); color
(Math.
max(l, tm
+ 1), r,
2 * v
+ 1, tm
+ 1, tr
); T[v] = T[2 * v] || T[2 * v + 1];
}
}
int n = nextInt();
G = new ArrayList<ArrayList<Integer>>();
for (int i = 0; i < n; i++) {
G.add(new ArrayList<Integer>());
}
for (int i = 0; i < n - 1; i++) {
int a = nextInt() - 1;
int b = nextInt() - 1;
G.get(a).add(b);
G.get(b).add(a);
}
timer = 0;
dfs(0, 0);
build(1, 0, n - 1);
int q = nextInt();
for (int i = 0; i < q; i++) {
int c = nextInt();
int v = nextInt() - 1;
if (c == 1) {
boolean up = get(tin[v], tout[v], 1, 0, n - 1);
color(tin[v], tout[v], 1, 0, n - 1);
if (up && v > 0) {
update(tout[parent[v]], 1, 0, n - 1);
}
} else if (c == 2) {
update(tout[v], 1, 0, n - 1);
} else {
out.println(get(tin[v], tout[v], 1, 0, n - 1) ? 0 : 1);
}
}
out.flush();
}
}
CmltcG9ydCBqYXZhLmlvLkJ1ZmZlcmVkUmVhZGVyOwppbXBvcnQgamF2YS5pby5JT0V4Y2VwdGlvbjsKaW1wb3J0IGphdmEuaW8uSW5wdXRTdHJlYW1SZWFkZXI7CmltcG9ydCBqYXZhLmlvLlByaW50V3JpdGVyOwppbXBvcnQgamF2YS5pby5TdHJlYW1Ub2tlbml6ZXI7CmltcG9ydCBqYXZhLnV0aWwuQXJyYXlMaXN0OwoKcHVibGljIGNsYXNzIFdhdGVyVHJlZSB7CgogICAgc3RhdGljIFN0cmVhbVRva2VuaXplciBpbjsKICAgIHN0YXRpYyBQcmludFdyaXRlciBvdXQ7CgogICAgc3RhdGljIGludCBuZXh0SW50KCkgdGhyb3dzIElPRXhjZXB0aW9uIHsKICAgICAgICBpbi5uZXh0VG9rZW4oKTsKICAgICAgICByZXR1cm4gKGludCkgaW4ubnZhbDsKICAgIH0KICAgIHN0YXRpYyBmaW5hbCBpbnQgTUFYTiA9IDUwMDAwNTsKICAgIHN0YXRpYyBBcnJheUxpc3Q8QXJyYXlMaXN0PEludGVnZXI+PiBHOwogICAgc3RhdGljIGludCB0aW1lcjsKICAgIHN0YXRpYyBpbnRbXSB0aW4gPSBuZXcgaW50W01BWE5dOwogICAgc3RhdGljIGludFtdIHRvdXQgPSBuZXcgaW50W01BWE5dOwogICAgc3RhdGljIGludFtdIHBhcmVudCA9IG5ldyBpbnRbTUFYTl07CgogICAgc3RhdGljIHZvaWQgZGZzKGludCB1LCBpbnQgcCkgewogICAgICAgIHBhcmVudFt1XSA9IHA7CiAgICAgICAgdGluW3VdID0gdGltZXI7CiAgICAgICAgZm9yIChpbnQgdiA6IEcuZ2V0KHUpKSB7CiAgICAgICAgICAgIGlmICh2ICE9IHApIHsKICAgICAgICAgICAgICAgIGRmcyh2LCB1KTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB0b3V0W3VdID0gdGltZXIrKzsKICAgIH0KICAgIHN0YXRpYyBib29sZWFuW10gVCA9IG5ldyBib29sZWFuWzggKiBNQVhOXTsKICAgIHN0YXRpYyBib29sZWFuW10gcHJvbWlzZSA9IG5ldyBib29sZWFuWzggKiBNQVhOXTsKCiAgICBzdGF0aWMgdm9pZCBidWlsZChpbnQgdiwgaW50IHRsLCBpbnQgdHIpIHsKICAgICAgICBpZiAodGwgPCB0cikgewogICAgICAgICAgICBpbnQgdG0gPSAodGwgKyB0cikgLyAyOwogICAgICAgICAgICBidWlsZCgyICogdiwgdGwsIHRtKTsKICAgICAgICAgICAgYnVpbGQoMiAqIHYgKyAxLCB0bSArIDEsIHRyKTsKICAgICAgICB9CiAgICAgICAgVFt2XSA9IHRydWU7CiAgICB9CgogICAgc3RhdGljIHZvaWQgcHVzaChpbnQgdikgewogICAgICAgIGlmIChwcm9taXNlW3ZdKSB7CiAgICAgICAgICAgIHByb21pc2Vbdl0gPSBmYWxzZTsKICAgICAgICAgICAgcHJvbWlzZVsyICogdl0gPSBwcm9taXNlWzIgKiB2ICsgMV0gPSB0cnVlOwogICAgICAgICAgICBUWzIgKiB2XSA9IFRbMiAqIHYgKyAxXSA9IGZhbHNlOwogICAgICAgIH0KICAgIH0KCiAgICBzdGF0aWMgYm9vbGVhbiBnZXQoaW50IGwsIGludCByLCBpbnQgdiwgaW50IHRsLCBpbnQgdHIpIHsKICAgICAgICBpZiAobCA+IHIpIHsKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgICBwdXNoKHYpOwogICAgICAgIGlmICh0bCA9PSBsICYmIHRyID09IHIpIHsKICAgICAgICAgICAgcmV0dXJuIFRbdl07CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgaW50IHRtID0gKHRsICsgdHIpIC8gMjsKICAgICAgICAgICAgcmV0dXJuIGdldChsLCBNYXRoLm1pbihyLCB0bSksIDIgKiB2LCB0bCwgdG0pCiAgICAgICAgICAgICAgICAgICAgfHwgZ2V0KE1hdGgubWF4KGwsIHRtICsgMSksIHIsIDIgKiB2ICsgMSwgdG0gKyAxLCB0cik7CiAgICAgICAgfQogICAgfQoKICAgIHN0YXRpYyB2b2lkIHVwZGF0ZShpbnQgcCwgaW50IHYsIGludCB0bCwgaW50IHRyKSB7CiAgICAgICAgcHVzaCh2KTsKICAgICAgICBUW3ZdID0gdHJ1ZTsKICAgICAgICBpZiAodGwgPCB0cikgewogICAgICAgICAgICBpbnQgdG0gPSAodGwgKyB0cikgLyAyOwogICAgICAgICAgICBpZiAocCA8PSB0bSkgewogICAgICAgICAgICAgICAgdXBkYXRlKHAsIDIgKiB2LCB0bCwgdG0pOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdXBkYXRlKHAsIDIgKiB2ICsgMSwgdG0gKyAxLCB0cik7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CgogICAgc3RhdGljIHZvaWQgY29sb3IoaW50IGwsIGludCByLCBpbnQgdiwgaW50IHRsLCBpbnQgdHIpIHsKICAgICAgICBpZiAobCA+IHIgfHwgcHJvbWlzZVt2XSkgewogICAgICAgICAgICByZXR1cm47CiAgICAgICAgfQogICAgICAgIGlmIChsID09IHRsICYmIHIgPT0gdHIpIHsKICAgICAgICAgICAgcHJvbWlzZVt2XSA9IHRydWU7CiAgICAgICAgICAgIFRbdl0gPSBmYWxzZTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBpbnQgdG0gPSAodGwgKyB0cikgLyAyOwogICAgICAgICAgICBjb2xvcihsLCBNYXRoLm1pbihyLCB0bSksIDIgKiB2LCB0bCwgdG0pOwogICAgICAgICAgICBjb2xvcihNYXRoLm1heChsLCB0bSArIDEpLCByLCAyICogdiArIDEsIHRtICsgMSwgdHIpOwogICAgICAgICAgICBUW3ZdID0gVFsyICogdl0gfHwgVFsyICogdiArIDFdOwogICAgICAgIH0KICAgIH0KCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB0aHJvd3MgSU9FeGNlcHRpb24gewogICAgICAgIGluID0gbmV3IFN0cmVhbVRva2VuaXplcihuZXcgQnVmZmVyZWRSZWFkZXIobmV3IElucHV0U3RyZWFtUmVhZGVyKFN5c3RlbS5pbikpKTsKICAgICAgICBvdXQgPSBuZXcgUHJpbnRXcml0ZXIoU3lzdGVtLm91dCk7CgogICAgICAgIGludCBuID0gbmV4dEludCgpOwogICAgICAgIEcgPSBuZXcgQXJyYXlMaXN0PEFycmF5TGlzdDxJbnRlZ2VyPj4oKTsKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykgewogICAgICAgICAgICBHLmFkZChuZXcgQXJyYXlMaXN0PEludGVnZXI+KCkpOwogICAgICAgIH0KICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IG4gLSAxOyBpKyspIHsKICAgICAgICAgICAgaW50IGEgPSBuZXh0SW50KCkgLSAxOwogICAgICAgICAgICBpbnQgYiA9IG5leHRJbnQoKSAtIDE7CiAgICAgICAgICAgIEcuZ2V0KGEpLmFkZChiKTsKICAgICAgICAgICAgRy5nZXQoYikuYWRkKGEpOwogICAgICAgIH0KCiAgICAgICAgdGltZXIgPSAwOwogICAgICAgIGRmcygwLCAwKTsKICAgICAgICBidWlsZCgxLCAwLCBuIC0gMSk7CgogICAgICAgIGludCBxID0gbmV4dEludCgpOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgcTsgaSsrKSB7CiAgICAgICAgICAgIGludCBjID0gbmV4dEludCgpOwogICAgICAgICAgICBpbnQgdiA9IG5leHRJbnQoKSAtIDE7CiAgICAgICAgICAgIGlmIChjID09IDEpIHsKICAgICAgICAgICAgICAgIGJvb2xlYW4gdXAgPSBnZXQodGluW3ZdLCB0b3V0W3ZdLCAxLCAwLCBuIC0gMSk7CiAgICAgICAgICAgICAgICBjb2xvcih0aW5bdl0sIHRvdXRbdl0sIDEsIDAsIG4gLSAxKTsKICAgICAgICAgICAgICAgIGlmICh1cCAmJiB2ID4gMCkgewogICAgICAgICAgICAgICAgICAgIHVwZGF0ZSh0b3V0W3BhcmVudFt2XV0sIDEsIDAsIG4gLSAxKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSBlbHNlIGlmIChjID09IDIpIHsKICAgICAgICAgICAgICAgIHVwZGF0ZSh0b3V0W3ZdLCAxLCAwLCBuIC0gMSk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBvdXQucHJpbnRsbihnZXQodGluW3ZdLCB0b3V0W3ZdLCAxLCAwLCBuIC0gMSkgPyAwIDogMSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgb3V0LmZsdXNoKCk7CiAgICB9Cn0K