func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<int> v[300010];   int centroid[300010], Next[300010], par[300010], sz[300010];   void dfs(int cur) {     sz[cur] = 1;     int maxx = 0;     Next[cur] = 0;     for (int u : v[cur])       if (u != par[cur]) {         dfs(u);         sz[cur] += sz[u];         if (sz[u] > maxx) {           maxx = sz[u];           Next[cur] = u;         }       }     if (maxx == 0) {       centroid[cur] = cur;       return;     }     int u = centroid[Next[cur]];     while (u != cur) {       if (sz[Next[u]] * 2 > sz[cur]) break;       u = par[u];     }     if (sz[Next[u]] * 2 > sz[cur]) u = Next[u];     centroid[cur] = u;   }   int main() {     int n, m, i;     scanf( %d , &n);     scanf( %d , &m);     for (i = 2; i <= n; ++i) {       scanf( %d , &par[i]);       v[i].push_back(par[i]);       v[par[i]].push_back(i);     }     sz[0] = 0;     dfs(1);     for (i = 0; i < m; ++i) {       int x;       scanf( %d , &x);       printf( %d n , centroid[x]);     }   }   