#include <iostream>
#include <vector>
#include <algorithm>

#define int long long

using namespace std;

void find_level(int v, vector<int>& p, vector<int>& level) {
    if (level[v] != -1) {
        return;
    }
    find_level(p[v], p, level);
    level[v] = level[p[v]] + 1;
}

signed main() {
    int n, q;
    cin >> n >> q;
    vector<int> p(n), s(n), v(q);
    for (int i = 1; i < n; ++i) {
        cin >> p[i];
        p[i]--;
    }
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    vector<int> level(n, -1);
    level[0] = 0;
    for (int i = 0; i < n; ++i) {
        if (level[i] == -1) {
            find_level(i, p, level);
        }
    }
    for (int i = 0; i < q; ++i) {
        cin >> v[i];
        cout << level[v[i] - 1] << " ";
    }

}
