func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T x, T y) {     if (x < y) swap(x, y);     while (y > 0) {       T f = x % y;       x = y;       y = f;     }     return x;   }   template <typename T>   pair<T, T> exgcd(T x, T y) {     if (x < y) swap(x, y);     pair<T, T> r = make_pair(1, 0);     while (y > 0) {       T f = x % y;       r = make_pair(r.second, r.first - (x / y) * r.second);       x = y;       y = f;     }     return r;   }   const int maxn = 1e5;   int n;   int P[maxn + 1], T[maxn + 1];   int SP[maxn + 1];   int TP[maxn + 1];   int lvl[maxn + 1];   vector<int> child[maxn + 1];   int bg[maxn + 1];   int ed[maxn + 1];   int tt = 0;   void dfs(int u, bool sp = false) {     bg[u] = tt++;     for (auto c : child[u]) lvl[c] = lvl[u] + 1, dfs(c);     ed[u] = tt++;   }   bool isAsc(int u, int v) { return bg[u] <= bg[v] && ed[v] <= ed[u]; }   int main(int argc, char *argv[]) {     std::cin.sync_with_stdio(false);     std::cin.tie(nullptr);     cin >> n;     {       for (int i = 1; i <= n; i++) {         cin >> P[i] >> T[i];         if (T[i] == 0) {           SP[i] = SP[P[i]];           TP[i] = i;         } else if (T[i] == 1) {           SP[i] = i;           TP[i] = TP[P[i]];         } else {           TP[i] = i;           SP[i] = i;         }         bg[i] = ed[i] = 0;       }       for (int i = 1; i <= n; i++) {         if (P[i] != -1) {           child[P[i]].push_back(i);         }       }       tt = 1;       for (int i = 1; i <= n; i++) {         if (!bg[i]) {           lvl[i] = 1;           dfs(i);         }       }       int q;       cin >> q;       while (q--) {         int t, u, v, ov;         cin >> t >> u >> v;         if (u == v) {           cout <<  NO  << endl;           continue;         }         if (t == 1) {           if ((isAsc(u, v) && lvl[SP[v]] <= lvl[u]))             cout <<  YES  << endl;           else             cout <<  NO  << endl;         } else {           int av = TP[v];           if (av != v && (isAsc(av, u) && lvl[SP[u]] <= lvl[av]))             cout <<  YES  << endl;           else {             int au = SP[u];             if (au != v && isAsc(au, v) && lvl[TP[v]] <= lvl[au])               cout <<  YES  << endl;             else               cout <<  NO  << endl;           }         }       }     }     return 0;   }   