#include <bits/stdc++.h>
#ifndef  WILEYNE
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#endif
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using ordered_set = __gnu_pbds::tree<int, __gnu_pbds::null_type,std::less<int>,__gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;





using ll = long long;
using ld = long double;

using namespace std;

const int MAX_N = (int)3e5+100;
const double eps = acos(-1);
const int INT_INF = (int)2e9+10;
const int MOD = (int)1e9+7;
auto seet = chrono::high_resolution_clock ::now().time_since_epoch().count();
mt19937 rng(seet);

int deep[MAX_N];
vector<int>graph[MAX_N];
int s[MAX_N];

void dfs(int v, int d){
    deep[v] = d;
    for(auto c:graph[v]){
        dfs(c,d+1);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#ifdef WILEYNE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int n,q;
    cin>>n>>q;
    for(int i = 2;i<=n;++i){
        int p;
        cin>>p;
        graph[p].push_back(i);
    }
    dfs(1,0);
    for(int i = 0;i<n;++i) cin>>s[i+1];
    for(int i = 0;i<q;++i){;
        int v;
        cin>>v;
        cout<<deep[v]<<" ";
    }

    return 0;
}
