func_code_string: #include <bits/stdc++.h>   #pragma comment(linker,  /STACK:200000000 )   using namespace std;   template <typename T>   inline T Abs(T x) {     return (x >= 0) ? x : -x;   }   template <typename T>   inline T sqr(T x) {     return x * x;   }   template <typename T>   inline string toStr(T x) {     stringstream st;     st << x;     string s;     st >> s;     return s;   }   template <typename T>   inline int bit(T mask, int b) {     return (b >= 0 && (mask & (T(1) << b)) != 0) ? 1 : 0;   }   inline int nextInt() {     int x;     if (scanf( %d , &x) != 1) throw;     return x;   }   inline long long nextInt64() {     long long x;     if (scanf( %lld , &x) != 1) throw;     return x;   }   inline double nextDouble() {     double x;     if (scanf( %lf , &x) != 1) throw;     return x;   }   const int INF = (int)1E9;   const long long INF64 = (long long)1E18;   const long double EPS = 1E-9;   const long double PI = 3.1415926535897932384626433832795;   const int MAXN = 500100;   const int OSN = (1 << 19) - 1;   int n, lst[MAXN], rst[MAXN], tree[2 * OSN + 10], tree0[2 * OSN + 10];   vector<int> g[MAXN], st;   void DFS(int v, int prev) {     lst[v] = int(st.size());     st.push_back(v);     for (int i = 0; i < (int)(g[v].size()); i++) {       int u = g[v][i];       if (u != prev) DFS(u, v);     }     rst[v] = int(st.size() - 1);   }   void update(int v, int value) {     v += OSN;     tree[v] = value;     while (v > 0) {       v = (v - 1) >> 1;       tree[v] = max(tree[v], value);     }   }   void update(int v, int l, int r, int ll, int rr, int value) {     if (l > rr || ll > r || ll > rr) return;     if (ll <= l && r <= rr) {       tree0[v] = value;       return;     }     int mid = (l + r) >> 1;     update(2 * v + 1, l, mid, ll, rr, value);     update(2 * v + 2, mid + 1, r, ll, rr, value);   }   int getMax(int v, int l, int r, int ll, int rr) {     if (l > rr || ll > r || ll > rr) return 0;     if (ll <= l && r <= rr) return tree[v];     int mid = (l + r) >> 1;     return max(getMax(2 * v + 1, l, mid, ll, rr),                getMax(2 * v + 2, mid + 1, r, ll, rr));   }   int getMax(int v, int l, int r, int x) {     if (l > x || x > r) return 0;     if (l == r) return tree0[v];     int mid = (l + r) >> 1;     int ans = tree0[v];     ans = max(ans, getMax(2 * v + 1, l, mid, x));     ans = max(ans, getMax(2 * v + 2, mid + 1, r, x));     return ans;   }   int check(int v) {     int t0 = getMax(0, 0, OSN, lst[v], rst[v]);     int t1 = getMax(0, 0, OSN, lst[v]);     return int(t0 < t1);   }   int main() {     n = nextInt();     for (int i = 0; i < (int)(n - 1); i++) {       int v = nextInt() - 1;       int u = nextInt() - 1;       g[v].push_back(u);       g[u].push_back(v);     }     DFS(0, 0);     int q = nextInt();     for (int i = 0; i < (int)(q); i++) {       int type = nextInt();       int v = nextInt() - 1;       if (type == 1) update(0, 0, OSN, lst[v], rst[v], i + 1);       if (type == 2) update(lst[v], i + 1);       if (type == 3) printf( %d n , check(v));     }     return 0;   }   