#include <bits/stdc++.h>

using ll = long long;
using namespace std;
ll mod = 1e9 + 7;
struct mod_ll {
    ll v = 0;
    mod_ll(ll nv = 0) {
        v = nv;
        if (v < 0 || v >= mod) {
            v = (v % mod + mod) % mod;
        }
    }
};
mod_ll operator + (mod_ll v1, mod_ll v2) {
    return (v1.v + v2.v >= mod ? v1.v + v2.v - mod : v1.v + v2.v);
}
mod_ll operator -(mod_ll v1, mod_ll v2) {
    return (v1.v - v2.v < 0 ? v1.v - v2.v + mod : v1.v - v2.v);
}
mod_ll operator *(mod_ll v1, mod_ll v2) {
    return (1LL * v1.v * v2.v) % mod;
}
bool operator == (mod_ll v1, mod_ll v2) {
    return v1.v == v2.v;
}
bool operator < (mod_ll v1, mod_ll v2) {
    return v1.v < v2.v;
}
void dfs(ll num, ll p, vector <ll> &up, vector <vector <ll>> &gr) {
    up[num] = p;
    for (ll next : gr[num]) {
        dfs(next, p, up, gr);
    }
}
bool cmp(pair <ll, ll> &a, pair <ll, ll> &b) {
    return a.first > b.first;
}
void dfs1(ll num, vector <vector <ll>> &gr, vector <ll> &counter) {
    for (ll next : gr[num]) {
        dfs1(next, gr, counter);
        counter[num] += counter[next];
    }
}
void solve3(ll n, vector <vector <ll>> &gr, vector <ll> &ind, vector <ll> &p, vector <ll> &prev, ll q) {
    vector <ll> counter(n, 0);
    for (ll i = 0; i < q; ++i) {
        fill(counter.begin(), counter.end(), 0);
        ll num;
        cin >> num;
        --num;
        for (ll j = 0; j < n; ++j) {
            if (ind[j] < ind[num]) {
                ++counter[j];
            }
        }
        ll ans = ind[num];
        dfs1(0, gr, counter);
        ll cur = prev[num], last = num;
        while (cur != - 1) {
            for (ll next : gr[cur]) {
                if (next != last) {
                    ans = min(ans, ind[num] - counter[next]);
                }
            }
            cur = prev[cur];
            last = prev[last];
        }
        cout << ans << '\n';
    }
}
void solve2(ll n, vector <vector <ll>> &gr, vector <ll> &ind, vector <ll> &p, vector <ll> &prev, ll q) {
    vector <ll> up(n);
    vector <ll> ans = ind;
    for (ll next : gr[0]) {
        dfs(next, next, up, gr);
    }
//    for (ll i = 0; i < n; ++i) {
//        cout << up[i]  + 1 << ' ';
//    }
//    cout << '\n';
//    for (ll i = 0; i < n; ++i) {
//        cout << p[i] + 1 << ' ';
//    }
//    cout << '\n';
    vector <ll> counter(n, 0);
    vector <pair <ll, ll>> cur;
    cur.push_back({0, 0});
    cur.push_back({0, 0});
    for (auto num : p) {
//        cout << num + 1 << '\n';
//        cout << ind[num] << '\n';
//        cout << cur[0].first << " " << cur[0].second + 1 << '\n';
//        cout << cur[1].first << " " << cur[1].second + 1 << '\n';
//        cout << '\n';
        if (cur[0].second == up[num]) {
//            cout << "GOOD" << '\n' << '\n';
            ans[num] = ind[num] - cur[1].first;
        } else {
            ans[num] = ind[num] - cur[0].first;
        }
        if (num != 0) {
            ++counter[up[num]];
            cur.push_back({counter[up[num]], up[num]});
            sort(cur.begin(), cur.end(), cmp);
            if (cur[0].second == cur[1].second) {
                swap(cur[1], cur[2]);
                cur.pop_back();
            } else {
                cur.pop_back();
            }
        }
    }
    for (ll i = 0; i < q; ++i) {
        ll num;
        cin >> num;
        --num;
        cout << ans[num] << ' ';
    }
    cout << '\n';
}
void solve() {
    ll n, q;
    cin >> n >> q;
    vector <vector <ll>> gr(n);
    vector <ll> prev(n, - 1);
    for (ll i = 1; i < n; ++i) {
        ll p;;
        cin >> p;
        --p;
        prev[i] = p;
        gr[p].push_back(i);
    }
    vector <ll> val(n);
    for (ll i = 0; i < n; ++i) {
        cin >> val[i];
    }
    set <pair <ll, ll>> now{};
    now.emplace(- val[0], 0);
    vector <ll> ind(n);
    ll time = 0;
    vector <ll> p{};
    while (!now.empty()) {
        ll num = now.begin()->second;
        p.push_back(num);
        ind[num] = time;
        ++time;
        now.erase(now.begin());
        for (auto next : gr[num]) {
            now.insert({- val[next], next});
        }
    }
    bool flag = true;
    for (ll i = 0; i < n; ++i) {
        if (prev[i] != 0 && prev[i] != i - 1) {
            flag = false;
        }
    }
//    for (ll i = 0; i < n; ++i) {
//        cout << p[i] << ' ';
//    }
//    cout << '\n';
    if (flag) {
//        cout << "bef" << '\n';
        solve2(n, gr, ind, p, prev, q);
        return;
    }
    if (q <= 100) {
        solve3(n, gr, ind, p, prev, q);
        return;
    }
    vector <ll> ans = ind;
    vector <ll> counter(n, 0);
    for (ll num : p) {
        ll cur = prev[num], last = num;
        while (cur != - 1) {
            for (auto next : gr[cur]) {
                if (next != last) {
                    ans[num] = min(ans[num], ind[num] - counter[next]);
                }
            }
            cur = prev[cur];
            last = prev[last];
        }
        cur = num;
        while (cur != - 1) {
            ++counter[cur];
            cur = prev[cur];
        }
    }
    for (ll i = 0; i < q; ++i) {
        ll num;
        cin >> num;
        --num;
        cout << ans[num] << ' ';
    }
    cout << '\n';
}
//vector <vector <ll>> get(vector <ll> &val, ll n, ll k) {
//    vector <vector <ll>> next(n + 1, vector <ll> (k, n));
//    vector <ll> now(k, n + 1);
//    for (ll i = n; i >= 0; --i) {
//        next[i] = now;
//        if (i != 0) {
//            now[val[i - 1]] = i;
//        }
//    }
//    return next;
//}
//void solve() {
//    ll N, n, M, m, k;
//    ll q;
//    cin >> N >> n >> M >> m >> k;
//    cin >> q;
//    vector <ll> a, b;
//    for (ll i = 0; i < n; ++i) {
//        ll len, v;
//        cin >> len >> v;
//        --v;
//        for (ll j = 0; j < len; ++j) {
//            a.push_back(v);
//        }
//    }
//    for (ll i = 0; i < m; ++i) {
//        ll len, v;
//        cin >> len >> v;
//        --v;
//        for (ll j = 0; j < len; ++j) {
//            b.push_back(v);
//        }
//    }
//    n = N;
//    m = M;
////    for (ll i = 0; i < n; ++i) {
////        cout << a[i] << ' ';
////    }
////    cout << '\n';
////    for (ll j = 0; j < m; ++j) {
////        cout << b[j] << ' ';
////    }
////    cout << '\n';
//    vector <vector <ll>> dp(n + 2, vector <ll> (m + 2, 0));
//    for (ll i = 0; i < m + 2; ++i) {
//        dp[n + 1][i] = 1;
//    }
//    for (ll i = 0; i < n + 2; ++i) {
//        dp[i][m + 1] = 1;
//    }
//    vector <vector <ll>> anext = get(a, n, k), bnext = get(b, m, k);
//    vector <ll> cur(k, 0);
////    for (ll i = 0; i < n + 1; ++i) {
////        for (ll j = 0; j < k; ++j) {
////            cout << anext[i][j] << ' ';
////        }
////        cout << '\n';
////    }
////    for (ll i = 0; i < m + 1; ++i) {
////        for (ll j = 0; j < k; ++j) {
////            cout << bnext[i][j] << ' ';
////        }
////        cout << '\n';
////    }
//    for (ll i = n; i >= 0; --i) {
//        ll sum = k;
//        fill(cur.begin(), cur.end(), 1);
//        for (ll j = m; j >= 0; --j) {
//            if (sum == k) {
//                dp[i][j] = 0;
//            } else {
//                dp[i][j] = 1;
//            }
//            if (j != 0) {
//                sum -= cur[b[j - 1]];
//                cur[b[j - 1]] = dp[anext[i][b[j - 1]]][j];
//                sum += cur[b[j - 1]];
//            }
//        }
//    }
////    for (ll i = 0; i < n + 2; ++i) {
////        for (ll j = 0; j < m + 2; ++j) {
////            cout << dp[i][j] << ' ';
////        }
////        cout << '\n';
////    }
//    for (ll i = 0; i < q; ++i) {
//        ll x, y;
//        cin >> x >> y;
//        cout << (dp[x][y] ? "Yes" : "No") << '\n';
//    }
//}
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll t = 1;
//    cin >> t;
    for (ll i = 0; i < t; ++i) {
        solve();
    }
}
