func_code_string: #include <bits/stdc++.h>   using namespace std;   const int mxnn = 300000 + 10, inf = 0x3f3f3f3f;   int n, q, a, cnt;   int head[mxnn], son[mxnn], ans[mxnn], fa[mxnn];   struct node {     int u, v, next;   } e[mxnn << 1];   void adde(int u, int v) {     e[++cnt].u = u;     e[cnt].v = v;     e[cnt].next = head[u];     head[u] = cnt;   }   void read(int &x) {     x = 0;     int f = 1;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = (x << 1) + (x << 3) + s -  0 ;       s = getchar();     }     x *= f;   }   void dfs(int u, int va) {     ans[u] = u;     for (int i = head[u]; i != -1; i = e[i].next) {       int v = e[i].v;       if (v == va) continue;       dfs(v, u);       son[u] += son[v];     }     for (int i = head[u]; i != -1; i = e[i].next) {       int v = e[i].v;       if (v == va) continue;       if (son[v] * 2 > son[u]) {         ans[u] = ans[v];         break;       }     }     while (son[u] > 2 * son[ans[u]]) ans[u] = fa[ans[u]];   }   int main() {     memset(head, -1, sizeof head);     read(n), read(q);     for (int i = 1; i <= n; ++i) son[i] = 1;     for (int i = 2; i <= n; ++i) {       read(a);       adde(a, i);       adde(i, a);       fa[i] = a;     }     dfs(1, 0);     while (q--) {       read(a);       printf( %d n , ans[a]);     }     return 0;   }   