#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, Q;
    cin >> n >> Q;
    vector<int> p(n);
    p[0] = 0;
    vector<vector<int>> gr(n);
    vector<int> h(n);
    for (int i = 1; i < n; i++) {
        cin >> p[i];
        p[i]--;
        h[i] = h[p[i]] + 1;
    }
    vector<int> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    for (int i = 0; i < Q; i++) {
        int x;
        cin >> x;
        x--;
        cout << h[x] << " ";
    }
}
