#pragma GCC optimize("O3", "unroll-loops")

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

#pragma GCC target("avx2")

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ost = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;
template<long long N, class T = long long>
using pii = array<T, N>;

constexpr ll mxn = 3e5;//3e5;

ll n;
ll ans[mxn];
vector<ll> arr[mxn];

void dfs(const ll& v = 0) {
    for (const auto& t : arr[v]){
        ans[t] = ans[v] + 1;
        dfs(t);
    }
}

int main() {
    //ost tt;
    //tt.insert(5);
    //tt.insert(10);
    //cout << tt.order_of_key(9);
    //cout << *tt.find_by_order(1);

    ll q;
    cin >> n >> q;
    for (ll i = 1; i < n; ++i){
        ll t;
        cin >> t;
        --t;
        arr[t].push_back(i);
    }
    ll x;
    for (ll i = 0; i < n; ++i) cin >> x;

    dfs();
    while(q--){
        ll t;
        cin >> t;
        cout << ans[--t] << ' ';
    }

    return 0;
}
