#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define fi first
#define se second
const ll inf = 1e17 + 7;
vector<ll> tree;
void build(ll v, ll l, ll r, vector<ll> &a) {
    if (r - l == 1) {
        tree[v] = a[l];
        return;
    }
    ll m = (l + r) / 2;
    build(2 * v + 1, l, m, a);
    build(2 * v + 2, m, r, a);
}

void update(ll v, ll l, ll r, ll ql, ll qr, ll x) {
    if (l >= qr || r <= ql) {
        return;
    }
    if (l >= ql && r <= qr) {
        tree[v] = x;
        return;
    }
    ll m = (l + r) / 2;
    update(2 * v + 1, l, m , ql, qr, x);
    update(2 * v + 2, m, r, ql, qr, x);
    tree[v] = tree[2 * v + 1] + tree[2 * v + 2];
}

vector<ll> col, h;

void dfs(ll v, ll color, vector<vector<ll>> &g) {
    col[v] = color;
    if (v == 0) {
        ll cnt = 0;
        for(auto u : g[v]) {
            h[u] = h[v] + 1;
            cnt++;
            dfs(u, cnt, g);
        }
    } else {
        for(auto u : g[v]) {
            h[u] = h[v] + 1;
            dfs(u, color, g);
        }
    }
}

void solve() {
    ll n, q;
    cin >> n >> q;
    h.resize(n);
    vector<vector<ll>> g(n);
    for(int i = 0; i < n - 1; ++i) {
        ll p;
        cin >> p;
        p--;
        g[p].push_back(i + 1);
    }
    vector<ll> s(n);
    for(int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    col.resize(n + 1);
    dfs(0, 0, g);
    vector<ll> ts;
    multiset<pair<ll, ll>> ms;
    for(auto u : g[0]) {
        ms.insert({-s[u], u});
    }
    while(!ms.empty()) {
        auto x = *ms.begin();
        ms.erase(ms.begin());
        for(auto u : g[x.se]) {
            ms.insert({-s[u], u});
        }
        ts.push_back(x.se);
    }
    vector<ll> ans(n, 0);
    vector<ll> ch(n + 1);
    ll mx = 0, prmx = 0;
    for(int i = 0; i < (int)ts.size(); ++i) {
        ll nw = mx;
        if (mx == ch[col[ts[i]]]) {
            nw = prmx;
        }
        ans[ts[i]] = i + 1 - nw;
        ch[col[ts[i]]]++;
        if (ch[col[ts[i]]] > mx) {
            prmx = mx, mx = ch[col[ts[i]]];
        } else {
            prmx = max(prmx, ch[col[ts[i]]]);
        }
    }
    for(int i = 0; i < q; ++i) {
        ll v;
        cin >> v;
        v--;
        cout << h[v] << ' ';
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll T = 1;
    //cin >> T;
    while(T--) {
        solve();
        cout << '\n';
    }
    return 0;
}
