//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
//#pragma GCC target("avx2")
using namespace std;
using ll = int64_t;
constexpr ll N = 3e5 + 1;
vector<ll> g[N];
ll s[N], d[N];

void dfs(ll v, ll dph) {
    d[v] = dph;
    for (auto &u : g[v]) {
        dfs(u, dph + 1);
    }
}

void solve() {
    ll n, q;
    cin >> n >> q;
    for (ll i = 2, p; i <= n; ++i) {
        cin >> p;
        g[p].push_back(i);
    }
    for (ll i = 1; i <= n; ++i) {
        cin >> s[i];
    }
    dfs(1, 0);
    while (q --> 0) {
        ll u;
        cin >> u;
        cout << d[u] << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll t = 1;
//    cin >> t;
    while (t --> 0) {
        solve();
    }

    return 0;
}
