#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 int long long
using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 3e5, inf = 1e9;

vector<vector<int>> g(N + 1);
int s[N + 1], gl[N + 1];
int ans[N + 1];
void dfs(int v){
    for(auto u : g[v]){
        ans[u] = ans[v] + 1;
    }
}

int32_t main()
{
    int n, q;
    cin >> n >> q;
    int p[n + 1];
    for(int i = 2;i <= n;i++){
        cin >> p[i];
        g[p[i]].push_back(i);
    }
    for(int i = 1;i <= n;i++){
        cin >> s[i];
    }
    dfs(1);
    for(int i = 1, x;i <= q;i++){
        cin >> x;
        cout << ans[x] << " ";
    }

    return 0;
}
