#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define mem(x, y) memset(x, y, sizeof x)
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define int ll

const int maxn = 3e5 + 5;
vector <int> g[maxn];
int s[maxn], d[maxn];

void dfs(int v, int h = 0) {
	d[v] = h;
	for (int u: g[v]) {
		dfs(u, h + 1);
	}
}

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int n, q;
	cin >> n >> q;
	for (int i = 2; i <= n; i++) {
		int p;
		cin >> p;
		g[p].push_back(i);
	}
	dfs(1);
	
	for (int i = 1; i <= n; i++) cin >> s[i];
	
	while (q--) {
		int v;
		cin >> v;
		cout << d[v] << ' ';
	}
	
	return 0;
}
