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

using namespace std;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend();

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ull> vull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef pair<double, double> pdd;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<pair<ld, ld>> vpld;
typedef string str;
typedef set<ll> sll;
typedef set<int> si;
typedef set<str> ss;
typedef set<pii> spii;
typedef multiset<int> msi;
typedef multiset<ll> msll;
typedef multiset<str> mss;
typedef multiset<pii> mspii;
typedef multiset<pll> mspll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef queue<int> qi;
typedef queue<ll> qll;
typedef queue<pair<ll, ll>> qpll;

using namespace __gnu_pbds;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

// ordered_set<ll> oset;
// oset.insert(2);
// oset.insert(5);
// oset.insert(100);
// cout << oset.order_of_key(15) << endl;
// *oset.find_by_order(1); -> 5
// gp_hash_table<ll, ll> gp;

template<typename T>
istream &operator>>(istream &in, vector<T> &a) {
    for (T &i : a) in >> i;
    return in;
}
 
template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &a) {
    in >> a.fi >> a.se;
    return in;
}
 
template<typename T1, typename T2>
ostream &operator<<(ostream &out, pair<T1, T2> &a) {
    out << a.fi << " " << a.se;
    return out;
}
 
template<typename T1, typename T2>
istream &operator>>(istream &in, vector<pair<T1, T2>> &a) {
    for (pair<T1, T2> &i : a) in >> i.fi >> i.se;
    return in;
}
 
template<typename T>
ostream &operator<<(ostream &out, const vector<T> &a) {
    for (auto i : a) {
        out << i << " ";
    }
    return out;
}
 
template<typename T1, typename T2>
ostream &operator<<(ostream &out, vector<pair<T1, T2>> &a) {
    for (pair<T1, T2> i : a) out << i.fi << " " << i.se << endl;
    return out;
}
 
template<typename T1>
ostream &operator<<(ostream &out, vector<vector<T1>> &a) {
    for (vector<T1> i : a) {
        for (T1 j : i) out << j << " ";
        out << endl;
    }
    return out;
}

template<typename T1, typename T2>
inline T1 min(T1 a, T2 b) {
    b = (T1) b;
    return a > b ? b : a;
}
 
template<typename T1, typename T2>
inline T1 max(T1 a, T2 b) {
    b = (T1) b;
    return a > b ? a : b;
}
 
template<typename T1, typename T2>
inline void amin(T1 &a, T2 b) {
    a = min(a, b);
}
 
template<typename T1, typename T2>
inline void amax(T1 &a, T2 b) {
    a = max(a, b);
}

double getTime() {
    return clock() / (double) CLOCKS_PER_SEC;
}

mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());

ll rndlr(ll l, ll r) {
    ll a = rnd() % (r - l + 1) + l;
    return a;
}

vvi g;
vi s;

vi depth;

void dfs(int v, int par = -1, int now_depth = 0) {
    depth[v] = now_depth;
    for (auto to : g[v]) {
        if (to == par) {
            continue;
        }
        dfs(to, v, now_depth + 1);
    }
}


void solve() {
    int n, q;
    cin >> n >> q;
    g.resize(n + 1);
    
    for (int i = 2; i <= n; ++i) {
        int par;
        cin >> par;
        g[par].push_back(i);
    }
    s.resize(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> s[i];
    }
    depth.resize(n + 1);
    dfs(1, -1, 0);

    while (q--) {
        int v;
        cin >> v;
        cout << depth[v] << "\n";
    }
}

int main() {
    setlocale(LC_ALL, "Russian");
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.precision(12);
    cout << fixed;
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
