#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//less_equal

//#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,bmi2,fma,popcnt")

#define int long long
#define x first
#define y second

vector<int> comp;

ordered_set<int> os;

int zapr, ans = 0, ans2 = 0;
vector<vector<int>> g;

int ttt = 0;
vector<int> tin, tout, glubb;

void tintout(int ind, int prev = -1, int glub = 0) {
    tin[ind] = ttt++;
    glubb[ind] = glub;
    for (auto &i : g[ind]) {
        if (i != prev) {
            tintout(i, ind, glub + 1);
        }
    }
    tout[ind] = ttt;
}
bool ancestor(int a, int b) {
    return tin[a] <= tin[b] && tin[b] <= tout[a];
}

void solve() {
    int n, q;
    cin >> n >> q;
    comp.resize(n);
    tin.resize(n);
    tout.resize(n);
    glubb.resize(n);
    g.resize(n);
    int a;
    for (int i = 1; i < n; i++) {
        cin >> a; a--;
        g[i].push_back(a);
        g[a].push_back(i);
    }
    tintout(0);
    for (auto& i : comp) {
        cin >> i;
    }/*
    for (auto& i : g) {
    
        for (auto& j : i) {
            cout << j << ' ';
        }cout << '\n';
    }cout << '\n';
    cout << "!!";*/
    for (int i = 0; i < q; i++) {
        cin >> zapr; zapr--;
        cout << glubb[zapr] << ' ';
    }
}

signed main() {
#ifdef lisie_bimbi
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    //cin.tie(nullptr);
    //ios_base::sync_with_stdio(false);
#endif
    int _ = 1;
    //cin >> _;
    while (_--) {
        solve();
    }
}