#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define size(t) (int)t.size()
#define pb push_back
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()

using namespace std;

const int N = 3e5 + 5;

vector <int> g[N];
int p[N], s[N], h[N];

void dfs(int i) {
    for (auto j:g[i]) {
        h[j] = h[i] + 1;
        dfs(j);
    }
}

void solve() {
    int n, q, i, j, k;
    cin >> n >> q;
    p[0] = -1;
    for (i = 1; i < n; i++) {
        cin >> p[i];
        p[i] --;
        g[p[i]].pb(i);
    }
    for (i = 0; i < n; i++) {
        cin >> s[i];
    }
    dfs(0);
    while (q--) {
        cin >> i;
        i --;
        cout << h[i] << ' ';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // LOCAL
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}



