func_code_string: #include <bits/stdc++.h>   const int kN = 100000 + 5;   int n, parent[kN], type[kN];   std::vector<int> edges[2][kN];   int left[2][kN], right[2][kN], stmp;   int top[2][kN];   void dfs(int color, int u, int root) {     left[color][u] = ++stmp;     top[color][u] = root;     for (int v : edges[color][u]) {       dfs(color, v, root);     }     right[color][u] = stmp;   }   bool is_ancestor(int color, int u, int v) {     return top[color][u] == top[color][v] && left[color][u] <= left[color][v] &&            right[color][v] <= right[color][u];   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &parent[i], &type[i]);       if (parent[i] != -1) edges[type[i]][parent[i]].emplace_back(i);     }     for (int c = 0; c < 2; ++c) {       stmp = 0;       for (int i = 1; i <= n; ++i) {         if (left[c][i] == 0) {           dfs(c, i, i);         }       }     }     int q;     scanf( %d , &q);     while (q--) {       int tp, u, v;       scanf( %d%d%d , &tp, &u, &v);       if (u == v || top[0][u] == v) {         puts( NO );         continue;       }       bool flag = false;       if (tp == 1) {         flag = is_ancestor(0, u, v);       } else {         flag = type[v] == 1 &&                (is_ancestor(0, top[1][v], u) || is_ancestor(1, top[0][u], v));       }       puts(flag ?  YES  :  NO );     }   }   