#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <tuple>
#include <deque>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int INF = 2 * 1e9;
const ll MAX = 1e15;
const ll MIN = -1e15;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-7;

vector<vector<int>> g;
vector<int> s, cnt, euler;


void bfs(int st) {
    set<pii> q = {{-s[st], st}};
    while (!q.empty()) {
        int u = q.begin()->second;
        euler.push_back(u);
        q.erase(q.begin());
        for (int v : g[u]) {
            q.insert({-s[v], v});
        }
    }
}
void solve() {
    int n, q; cin >> n >> q;
    g.assign(n, {});
    for (int u = 1; u < n; u++) {
        int p; cin >> p;
        p--;
        g[p].push_back(u);
    }
    s.assign(n, 0);
    for (int u = 0; u < n; u++) cin >> s[u];
    bfs(0);
    cnt.assign(n, 0);
    for (int i = 0; i < n; i++) {
        cnt[euler[i]] = i;
    }
    while (q--) {
        int u; cin >> u;
        u--;
        cout << cnt[u] << " ";
    }
}

signed main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int t = 1;
    //cin >> t;
    while (t--) solve();
}
