#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
using namespace std;
using ll = long long;
using ull = unsigned long long;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//
//template <class T> using ordered_set = tree<T, null_type, less<T>,
//        rb_tree_tag, tree_order_statistics_node_update>;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

mt19937 rnd(time(0));

vector <vector <int>> g;
vector <int> p, s, pred;

priority_queue <pair<int, int>> q;

void dfs(int v) {
    p.push_back(v);
    for (auto to : g[v]) {
        if (v != pred[v]) {
            q.push({s[to], to});
        }
    }
    if (!q.empty()) {
        auto [w, to] = q.top();
        q.pop();
        dfs(to);
    }
}

vector <int> tin, tout;
int timer = 0;
vector <int> e;

void dfs2(int v, int pr, int k) {
    e[v] = k;
    for (auto to : g[v]) {
        if (to != pr) {
            dfs2(to, v, k);
        }
    }
}

bool upper(int a, int b) {
    return tin[a] <= tin[b] && tout[a] >= tout[b];
}

int main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0); std::cout.tie(0);
    int n, q;
    cin >> n >> q;
    g.resize(n); pred.resize(n); s.resize(n);
    pred[0] = -1;
    for (int i = 1; i < n; i++) {
        cin >> pred[i];
        pred[i]--;
        g[pred[i]].push_back(i);
    }
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    dfs(0);
    tin.resize(n); tout.resize(n);
    e.resize(n);
    for (auto to : g[0]) {
        dfs2(to, 0, to);
    }
    vector <int> ans(n, INF);
    for (int i = 0; i < n; i++) {
        ans[p[i]] = i;
    }
    set <pair<int, int>> st;
    unordered_map <int, int> mp;
    st.insert({0, -1}); st.insert({0, -2});
    for (int i = 1; i < p.size(); i++) {
        int v = p[i];
        auto r1 = *(--st.end());
        st.erase(--st.end());
        auto r2 = *(--st.end());
        if (r1.second == e[v]) {
            ans[v] = min(ans[v], i - r2.first);
        } else {
            ans[v] = min(ans[v], i - r1.first);
        }
        st.insert(r1);
        mp[e[v]]++;
        st.erase({mp[e[v]] - 1, e[v]});
        st.insert({mp[e[v]], e[v]});
    }
    while (q--) {
        int v;
        cin >> v;
        cout << ans[v - 1] << ' ';
    }
    return 0;
}
