#include <bits/stdc++.h>   using namespace std;   double pi = acos(-1);   long long power(long long a, long long b) {     long long p_res = 1;     while (b > 0) {       if (b % 2 == 1) {         p_res *= a;         b--;       }       a *= a;       b /= 2;     }     return p_res;   }   int cc[300001];   int ans[300001];   set<pair<int, int> > ss;   set<pair<int, int> >::iterator it;   vector<int> adj[300001];   int n, q;   int dfs(int here) {     int res = 1;     for (int i = 0; i < adj[here].size(); i++) {       res += dfs(adj[here][i]);     }     cc[here] = res;     return res;   }   void centroid(int here, int prev) {     int mx = 0;     for (int i = 0; i < adj[here].size(); i++) {       int next = adj[here][i];       mx = max(mx, cc[next]);     }     if (2 * mx <= cc[here])       ans[here] = here;     else       ss.insert(make_pair(cc[here], here));     it = ss.lower_bound(make_pair(2 * mx, -1));     while (it != ss.end()) {       int v = it->first;       int i = it->second;       if (v > 2 * cc[here]) break;       if (2 * mx <= v && 2 * (v - cc[here]) <= v) {         ans[i] = here;         ss.erase(it++);       } else         it++;     }     for (int i = 0; i < adj[here].size(); i++) {       centroid(adj[here][i], here);     }   }   int main() {     scanf( %d %d , &n, &q);     for (int i = 2; i <= n; i++) {       int v;       scanf( %d , &v);       adj[v].push_back(i);     }     dfs(1);     centroid(1, -1);     for (int i = 0; i < q; i++) {       int v;       scanf( %d , &v);       printf( %d n , ans[v]);     }     return 0;   }   