func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   vector<vector<int> > graph, trees, chains;   vector<int> head, sub, mxs, mp, idx;   int dfs(int ind = 0) {     sub[ind] = 1;     mxs[ind] = 0;     for (auto u : graph[ind]) {       sub[ind] += dfs(u);       mxs[ind] = max(mxs[ind], sub[u]);     }     return sub[ind];   }   void HLD(int ind = 0, int chain = 0) {     pair<int, int> mx = {INT_MIN, INT_MIN};     if (chains[chain].empty()) head[chain] = ind;     chains[chain].push_back(ind);     mp[ind] = chain;     idx[ind] = chains[chain].size() - 1;     for (auto u : graph[ind]) {       mx = max(mx, make_pair(sub[u], u));     }     if (mx.first >= 0) {       HLD(mx.second, chain);       for (auto u : graph[ind]) {         if (u == mx.second) continue;         chains.push_back(vector<int>());         head.push_back(0);         HLD(u, chains.size() - 1);       }     }   }   int x;   void build(int n = 0, int l = 0, int r = chains[x].size() - 1) {     if (l == r) {       trees[x][n] = mxs[chains[x][l]];       return;     }     int md = (l + r) >> 1;     build(2 * n + 1, l, md);     build(2 * n + 2, md + 1, r);     trees[x][n] = min(trees[x][2 * n + 1], trees[x][2 * n + 2]);   }   int K, ind;   pair<bool, int> qry(int n = 0, int l = 0, int r = chains[x].size() - 1) {     if (l == r) {       return {K >= trees[x][n], chains[x][l]};     }     int md = (l + r) >> 1;     if (ind <= md && trees[x][2 * n + 1] <= K) {       return qry(2 * n + 1, l, md);     } else if (ind <= r && trees[x][2 * n + 2] <= K)       return qry(2 * n + 2, md + 1, r);     else       return {false, -1};   }   void s(int &x) {     register int c = getchar();     x = 0;     for (; (c < 48 || c > 57); c = getchar())       ;     for (; c > 47 && c < 58; c = getchar()) {       x = (x << 1) + (x << 3) + c - 48;     }   }   int main() {     int N, Q, u, v;     s(N), s(Q);     graph.resize(N);     mxs.resize(N);     sub.resize(N);     mp.resize(N);     idx.resize(N);     for (int i = 1; i < N; i++) {       v = i;       s(u);       u--;       graph[u].push_back(v);     }     dfs();     chains.push_back(vector<int>());     head.push_back(0);     HLD();     trees.resize(chains.size());     for (x = 0; x < (int)chains.size(); x++) {       trees[x].resize(4 * chains[x].size());       build();     }     while (Q--) {       s(v);       v--;       x = mp[v];       K = sub[v] / 2;       printf( %d n , qry().second + 1);     }     return 0;   }   