#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <climits>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<ll, ll>;

#define all(v) v.begin(), v.end()
#define len(v) (ll)v.size()

mt19937 rnd(525252);

const ll INF = 1e18, SZ = 1e6, MOD = 1e9 + 7;
const ld eps = 1e-8, pi = acosl(-1);

void dfs(vector<vector<ll>>& g, vector<ll>& h, ll u) {
	for (auto& v : g[u]) {
		h[v] = h[u] + 1;
		dfs(g, h, v);
	}
}

void solve() {
	ll n, q; cin >> n >> q;
	vector<vector<ll>>g(n);
	for (ll i = 1; i < n; ++i) {
		ll p; cin >> p;
		g[p - 1].push_back(i);
	}
    vector<ll>s(n);
    for (auto &i : s) cin >> i;
	vector<ll>h(n, 0);
	dfs(g, h, 0);
	while (q--) {
		ll v; cin >> v;
		v--;
		cout << h[v] << ' ';
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout.precision(20);
	ll t = 1;

//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
//    cin >> t;

	while (t--) {
		solve();
		cout << '\n';
	}
}
