#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define pii pair<int, int>
#define f first
#define s second
#define ld long double

using namespace std;
using namespace __gnu_pbds;
using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rnd(time(0));

const int MAXN = 3e5;
vector<int> g[MAXN];
int h[MAXN], s[MAXN];

void solve()
{
    int n, q; cin >> n >> q;
    for(int i = 0; i<n; ++i)
        g[i].clear();
    h[0] = 0;
    for(int i = 1; i<n; ++i)
    {
        int x; cin >> x; --x;
        g[x].push_back(i);
        h[i] = h[x]+1;
    }
    for(int i = 0; i<n; ++i) cin >> s[i];
    for(int i = 0; i<q; ++i)
    {
        int v; cin >> v; -- v;
        cout << h[v] << " ";
    }
}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1;
    //freopen("in.txt", "r", stdin); int t; cin >> t;
    //freopen("out.txt", "w", stdout);
    while(t--)
        solve();
    return 0;
}
