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

using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;
using o_set = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;

//find_by_order()
//order_of_key()

int n, q;

vector<vector<int>> g;
vector<int> p, s, d;

void dfs(int v) {
    d[v] = d[p[v]] + 1;
    for (auto to : g[v]) {
        if (to != p[v]) {
            dfs(to);
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> q;
    g.resize(n);
    p.reserve(n);
    s.resize(n);
    d.resize(n, 0);
    p[0] = -1;
    d[0] = 0;
    for (int i = 1; i < n; i++) {
        cin >> p[i];
        p[i]--;
        g[i].push_back(p[i]);
        g[p[i]].push_back(i);
    }
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    for (auto to : g[0]) {
        dfs(to);
    }
    while (q--) {
        int v;
        cin >> v;
        v--;
        cout << d[v] << ' ';
    }
    return 0;
}
