//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
template<class T> using ordered_set = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;
//using ld = long double;

#define all(x) begin(x), end(x)
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
vector<ll> h;

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

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

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll t = 1;
//    cin >> t;
    while (t--) solve(), cout << '\n';
    return 0;
}
