#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int n, q;

vector<vector<int>> g;
vector<int> h;
vector<int> s;

void dfs(int id) {
    for (int const &e : g[id]) {
        h[e] = h[id] + 1;
        dfs(e);
    }
}

void solve() {
    cin >> n >> q;
    g.resize(n);
    h.resize(n);
    s.resize(n);
    int t;
    for (int i = 1; i < n; ++i) {
        cin >> t;
        g[t - 1].push_back(i);
    }
    dfs(0);
    for (int &e : s) cin >> e;
    for (int i = 0; i < q; ++i) {
        cin >> t;
        cout << h[t - 1] << ' ';
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    solve();
}