#include <bits/stdc++.h>
using namespace std;
#define ll long long

vector<vector<int>> g;
vector<int> deep;

void dfs(int v) {
    for (int to : g[v]) {
        deep[to] = deep[v] + 1;
        dfs(to);
    }
}

void solve() {
    int n, q; cin >> n >> q;
    g.resize(n);
    deep.resize(n);
    for (int i = 1; i < n; ++i) {
        int x; cin >> x;
        g[x-1].push_back(i);
    }
    vector<int> c(n);
    for (int i = 0; i < n; ++i) cin >> c[i];
    deep[0] = 0;
    dfs(0);

    while (q--) {
        int x; cin >> x;
        cout << deep[x-1] << '\n';
    }
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int ttt = 1;
    //cin >> ttt;
    while (ttt--) {
        solve();
    }
}
