#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cstdint>
using namespace std;
#define int long long

void solution();

int32_t main() {
#ifdef LOCAL
    freopen("test", "r", stdin);
    freopen("out", "w", stdout);
#endif

    int t = 1;
    // cin >> t;
    while (t--) {
        solution();
    }
}


void solution() {
    int n, q;
    cin >> n >> q;

    vector<int> p(n);
    for (int i = 1; i < n; ++i) {
        cin >> p[i];
        p[i]--;
    }

    vector<int> s(n);
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }

    vector<int> num(n, -1);
    num[0] = 0;
    for (int i = 0; i < n; ++i) {
        if (num[i] != -1) continue;
        int x = i;
        int cnt = 0;
        while (num[x] == -1) {
            x = p[x];
            cnt++;
        }
        cnt += num[x];
        x = i;
        while (num[x] == -1) {
            num[x] = cnt--;
            x = p[x];
        }
    }

    while (q--) {
        int x;
        cin >> x;
        x--;
        
        cout << num[x] << ' ';
    }
}