
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define int long long
const int N = 3e5 + 3;
vector<int> g[N];
int s[N];
int n;
set<int> nowg[N];
vector<int> ob;
void calc(){
    //vector<bool> was(n, false);
    for (int i = 0 ;i < n; i++){
        nowg[i].clear();
        for (auto el : g[i]){
            nowg[i].insert(el);
        }
    }
    int root = 0;
    int res = 0;
    while (!nowg[root].empty()){
        //cout << root << "\n";
        ob.push_back(root);
        res++;
        int bst = -1;
        for (auto el : nowg[root]){
            if (bst == -1 ){
                bst = el;
            } else if (s[el] > s[bst]){
                bst = el;
            }
        }
        for (auto el : nowg[root]){
            nowg[el].erase(root);
            if (el != bst){
                nowg[bst].insert(el);
            }
        }
        nowg[root].clear();
        root = bst;
    }
    ob.push_back(root);
}
signed main(){
    //ios::sync_with_stdio(0);
    //cin.tie(0);
    int q;
    cin >> n >>  q;
    for (int i = 1; i < n; i++){
        int x;
        cin >> x;
        x--;
        g[i].push_back(x);
        g[x].push_back(i);
    }
    for (int i = 0 ;i < n; i++){
        cin >> s[i];
    }
    calc();
    vector<int> pos(n);
    for (int i = 0 ;i < n; i++){
        pos[ob[i]] = i;
    }
    while (q--){
        int v;
        cin >> v;
        v--;
        if (pos[v] <= 1){
            cout << pos[v] << " ";
        } else {
            cout << pos[v] - 1 << " ";
        }
    }
}
