#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#define endl '\n'
//#define int long long

using namespace std;

vector<int> tin, tout;

int T = 0;

void cnttime(int v, vector<vector<int>> &g) {
    tin[v] = T;
    T++;
    for (auto u : g[v]) {
        cnttime(u, g);
    }
    tout[v] = T;
    T++;
}

bool parent(int v, int u) {
    return (tin[v] <= tin[u] && tout[u] <= tout[v]);
}

signed main() {
    int n, q;
    cin >> n >> q;
    tin.resize(n);
    tout.resize(n);
    vector<vector<int>> g(n);
    vector<int> pr(n, -1);
    int x;
    for (int i = 1; i < n; ++i) {
        cin >> x;
        x--;
        pr[i] = x;
        g[x].push_back(i);
    }
    cnttime(0, g);
    set<pair<int, int>> dd;
    vector<int> ord;
    vector<int> c(n);
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
    }
    dd.insert({c[0], 0});
    while (!dd.empty()) {
        auto it = dd.end();
        it--;
        int v = it -> second;
        ord.push_back(v);
        dd.erase(it);
        for (auto u : g[v]) {
            dd.insert({c[u], u});
        }
    }
    vector<int> ask(n, -1);
    vector<pair<int, int>> ans;
    for (int i = 0; i < q; ++i) {
        cin >> x;
        x--;
        ask[x] = i;
    }
    set<pair<int, int>> cur;
    vector<int> dp(n);
    if (ask[0] != -1) {
        ans.push_back({ask[0], 0});
    }
    for (int i = 1; i < n; ++i) {
        auto u = ord[i];
        int cc = u;
        dp[u] = 1;
        cur.insert({-dp[u], u});
        cc = pr[cc];
        while (cc != 0) {
            cur.erase({-dp[cc], cc});
            dp[cc]++;
            cur.insert({-dp[cc], cc});
            cc = pr[cc];
        }
        if (ask[u] != -1) {
            int mx = 0;
            for (auto it = cur.begin(); it != cur.end(); ++it) {
                if (!parent((it -> second), u)) {
                    mx = max(mx, -(it -> first));
                    break;
                }
            }
            ans.push_back({ask[u], i - mx});
        }
    }
    sort(ans.begin(), ans.end());
    for (int i = 0; i < q; ++i) {
        cout << ans[i].second << " ";
    }
    cout << endl;
    return 0;
}
