// #include <string>
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

using ld = long double;
using ll = long long;

//#define int long long

int n;
vector<vector<int>> g;
vector<int> p, s, h;

void solve() {
    int q, x;
    cin >> n >> q;
    g.resize(n);
    p.resize(n);
    s.resize(n);
    h.resize(n);
    p[0] = -1;
    h[0] = 0;
    for (int i = 1; i < n; ++i) {
        cin >> p[i];
        p[i]--;
        g[i].push_back(p[i]);
        g[p[i]].push_back(i);

        h[i] = h[p[i]] + 1;
    }
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    for (int i = 0; i < q; ++i) {
        cin >> x;
        x--;
        cout << h[x] << ' ';
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int tt = 1;
    //cin >> tt;
    for (int i = 0; i < tt; ++i) {
        solve();
        //cout << '\n';
    }
}