#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr ll INF = 1e18;

void solve() {
    ll n, q;
    cin >> n >> q;
    vector<ll> p(n), ch(n, -1);
    p[0] = -1;
    vector<vector<ll>> g(n);
    for (ll i = 1; i < n; ++i) {
        cin >> p[i];
        p[i]--;
        if (p[i] > 0) {
            ch[p[i]] = i;
        }
        g[i].push_back(p[i]);
        g[p[i]].push_back(i);
    }

    vector<ll> s(n);
    for (ll i = 0; i < n; ++i) {
        cin >> s[i];
        s[i]--;
    }

//    vector<ll> paths;
//    for (ll i = 1; i < n; ++i) {
//        if (p[i] == 0) {
//            paths.push_back(i);
//        }
//    }
//    ll k = paths.size();
//
//    vector<ll> ans(n, -1);

    vector<ll> depth(n);
    depth[0] = 0;
    for (ll i = 1; i < n; ++i) {
        depth[i] = depth[p[i]] + 1;
    }
    for (ll i = 0; i < q; ++i) {
        ll v;
        cin >> v;
        cout << depth[v - 1] << ' ';
    }
    cout << '\n';
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}
