#include <bits/stdc++.h>
//#define int long long

using namespace std;
using ll = long long;
using ld = long double;
const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 3e5 + 69;

vector<vector<int>> g;
vector<int> h;
void dfs(int v, int p = -1) {
    for (int u : g[v]) {
        if (u != p) {
            h[u] = h[v] + 1;
            dfs(u, v);
        }
    }
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> par(n);
    g.resize(n);
    for (int i = 1; i < n; ++i) {
        int v;
        cin >> v;
        --v;
        g[v].push_back(i);
    }
    int s;
    for (int i = 0; i < n; ++i) cin >> s;
    h.resize(n);
    dfs(0);
    while (q--) {
        int v;
        cin >> v;
        cout << h[v - 1 ] << " ";
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}
