#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <math.h>
#include <string>
#include <vector>
#include <chrono>
#include <random>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
#include <set>
#define endl '\n'

using namespace std;
using i64 = long long;
using ld = long double;

const i64 INF = 1e18 + 5;

mt19937 rnd(29);

const i64 S = 1005, K = 3e5 + 10;
vector <i64> p[S], pRev[S], gr[K];
i64 val[S];
i64 ans[S][S];

void simulate(i64 sq, i64 ind) {
	i64 t = 0;
	ans[sq][ind] = t++;
	while (p[sq].size()) {
		i64 newSq = 0, vals = -1;
		for (auto x : p[sq]) {
			if (val[x] > vals) {
				vals = val[x];
				newSq = x;
			}
		}
		for (auto x : p[sq]) {
			if (x != newSq) {
				p[newSq].push_back(x);
			}
		}
		p[sq].clear();
		ans[newSq][ind] = t++;
		sq = newSq;
	}
	return;
}

i64 pred[K], sumUp[K];
vector <i64> d;

void dfs(i64 v, i64 pr) {
	pred[v] = pr;
	for (auto x : gr[v]) {
		if (pr == 1) {
			sumUp[x] = 1;
			dfs(x, x);
			d.push_back(x);
		}
		else {
			sumUp[x] = sumUp[v] + 1;
			dfs(x, pr);
		}
	}
}

int main() {
	#ifdef _DEBUG
		freopen("input.txt", "r", stdin);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	i64 n, q; cin >> n >> q;

	if (n <= 1000 && q <= 1000) {
		for (i64 x = 2; x <= n; ++x) {
			i64 pr; cin >> pr;
			p[pr].push_back(x);
		}

		for (i64 x = 1; x <= n; ++x) {
			cin >> val[x];
			pRev[x] = p[x];
		}

		for (i64 x = 1; x <= n; ++x) {
			i64 pre = val[x];
			val[x] = 0;
			simulate(1, x);
			for (i64 y = 1; y <= n; ++y) {
				p[y] = pRev[y];
			}
			val[x] = pre;
		}

		for (i64 x = 1; x <= q; ++x) {
			i64 answer = INF;
			i64 k; cin >> k;
			for (i64 y = 1; y <= n; ++y) {
				answer = min(answer, ans[k][y]);
			}
			cout << answer << " ";
		}
	}
	else {
		bool ok = true;
		for (i64 x = 2; x <= n; ++x) {
			i64 pr; cin >> pr;
			gr[pr].push_back(x);
			if (pr != 1 && pr != x - 1) ok = false;
		}
		if (ok) {
			for (i64 x = 1; x <= n; ++x) {
				cin >> val[x];
			}
			dfs(1, 1);
			for (i64 x = 1; x <= q; ++x) {
				i64 k; cin >> k;
				if (k == 1) {
					cout << 0 << " ";
				}
				else {
					cout << sumUp[k] << " ";
				}
			}
		}
		else {
			assert(false);
		}
		
	}
}