func_code_string: #include <bits/stdc++.h>   using namespace std;   int N, type[100005];   int Tm, in[100005], out[100005];   int par[100005][20];   bool comp[100005][20][2];   vector<int> G[100005];   void dfs(int nd) {     in[nd] = ++Tm;     for (int i = 0; i < G[nd].size(); i++) {       int ch = G[nd][i];       if (ch == par[nd][0]) continue;       comp[ch][0][type[ch]] = 1;       dfs(ch);     }     out[nd] = ++Tm;   }   int LCA(int u, int v) {     if ((in[u] <= in[v] && out[u] >= out[v])) return u;     for (int i = 20 - 1; i >= 0; i--)       if (!(in[par[u][i]] <= in[v] && out[par[u][i]] >= out[v])) u = par[u][i];     return par[u][0];   }   bool get(int u, int lca, int fl) {     if ((in[u] <= in[lca] && out[u] >= out[lca])) return false;     bool x = true;     for (int i = 20 - 1; i >= 0; i--)       if (!(in[par[u][i]] <= in[lca] && out[par[u][i]] >= out[lca])) {         x = x && comp[u][i][fl];         u = par[u][i];       }     x = x && comp[u][0][fl];     return x;   }   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       scanf( %d , &par[i][0]);       scanf( %d , &type[i]);       if (par[i][0] != -1) G[par[i][0]].push_back(i);     }     for (int i = 1; i <= N; i++)       if (par[i][0] == -1) {         par[i][0] = i;         dfs(i);       }     for (int i = 1; i < 20; i++)       for (int j = 1; j <= N; j++) {         par[j][i] = par[par[j][i - 1]][i - 1];         for (int fl = 0; fl < 2; fl++)           comp[j][i][fl] = comp[j][i - 1][fl] && comp[par[j][i - 1]][i - 1][fl];       }     int Q;     scanf( %d , &Q);     for (int i = 0; i < Q; i++) {       int tp, u, v;       scanf( %d , &tp);       scanf( %d , &u);       scanf( %d , &v);       int lca = LCA(u, v);       if (v == lca) {         puts( NO );       } else {         if (tp == 1) {           if (u == lca && get(v, lca, 0))             puts( YES );           else             puts( NO );         } else {           if (u == lca && get(v, lca, 1))             puts( YES );           else if (u != lca && get(u, lca, 0) && get(v, lca, 1))             puts( YES );           else             puts( NO );         }       }     }   }   