#include<bits/stdc++.h>

using namespace std;
#define int long long

vector<int>p;
vector<int>s;
vector<int>deep;
vector<vector<int>>g;

void dfs(int v){
    for(auto it : g[v]){
        deep[it] = deep[v]+1;
        dfs(it);
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,q;
    cin>>n>>q;
    p.resize(n);
    s.resize(n);
    deep.resize(n);
        g.resize(n);
    for(int i = 1;i<n;++i){
        cin>>p[i];
        p[i]--;
        g[p[i]].push_back(i);
    }
    p[0] = -1;
    for(int i = 0;i<n;++i){
        cin>>s[i];
    }
    dfs(0);
    while(q--){
        int v;
        cin>>v;
        v--;
        cout<<deep[v]<<"\n";
    }
}