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

#define int long long

using namespace std;

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, q;
	cin >> n >> q;
	vector<int>p(n);
	vector<vector<int>>g(n);
	for (int i = 1; i < n; ++i) {
		int x;
		cin >> x;
		x--;
		g[x].push_back(i);
		if (x != 0&&p[x]!=0) {
			x = p[x];
		}
		p[i] = x;
	}
	vector<int>s(n);
	for (int i = 0; i < n; ++i)cin >> s[i];
	vector<int>v;
	set<pair<int, int>>lol;
	vector<int>cnt(n);
	pair<int, int>x1 = { 0,-1 };
	pair<int, int>x2 = { 0,-1 };
	vector<int>ans(n);
	ans[0] = 0;
	lol.insert({ -s[0],0 });
	for (int i = 0; i < n; ++i) {
		int opa = i;
		int u = lol.begin()->second;
		if (x1.second != u && x1.second != p[u]) {
			opa = min(opa, i - x1.first);
		}
		if (x2.second != u && x2.second != p[u]) {
			opa = min(opa, i - x2.first);
		}
		ans[u] = opa;
		//int u = lol.begin()->second;
		v.push_back(u);
		lol.erase(lol.begin());
		for (int x : g[u]) {
			lol.insert({ -s[x], x });
		}
		pair<int, int>cnt1 = { 0,-2 };
		if (p[u] != 0) {
			cnt[p[u]]++;
			cnt1 = { cnt[p[u]],p[u] };
		}
		else if(u!=0){
			cnt[u]++;
			cnt1 = { cnt[u],u };
		}
		int ok = 1;
		if (x1.second == cnt1.second) {
			x1 = cnt1;
			ok = 0;
		}
		else if (x2.second == cnt1.second) {
			x2 = cnt1;
			ok = 0;
		}
		if (x1.first < x2.first) {
			swap(x1, x2);
		}
		if (ok) {
			if (cnt1.first > x1.first) {
				x2 = x1;
				x1 = cnt1;
			}
			else if (cnt1.first > x2.first) {
				x2 = cnt1;
			}
		}
	}
	for (; q > 0; --q) {
		int x;
		cin >> x;
		x--;
		cout << ans[x] << ' ';
	}
	return 0;
}