//#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> query;

void fill_q(vector<vector<ll>> &g, vector<ll> &s, ll st){
    ll now = st;
    query.push_back(st);
    while (true){
        ll h = -1;
        for (auto &x: g[now]) if (h == -1 || s[x] > s[h]) h = x;
        if (h == -1) return;
        query.push_back(h);
        for (auto &x: g[now]) if (x != h) g[h].push_back(x);
        now = h;
    }
}

void solve() {
    ll n, q;
    cin >> n >> q;
    vector<ll> p(n);
    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;
    fill_q(g, s, 0);
    vector<ll> ans(n);
    for (int i=0; i<n; ++i) ans[query[i]] = i;
    while (q--){
        int x;
        cin >> x;
        --x;
        cout << max((ll)(x ? 1 : 0), ans[x] - 1) << ' ';
    }
}

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;
}
