#include <algorithm>
#include <iostream>
#include <vector>

#define int long long
constexpr int INF = 4e18;

std::vector<std::vector<int>> g;
std::vector<int> p, s, sz, h;

void dfs(int v)
{
    h[v] = h[p[v]] + 1;
    sz[v] = 1;
    for (auto u : g[v]) {
        dfs(u);
        sz[v] += sz[u];
    }
}

void solve()
{
    int n, q;
    std::cin >> n >> q;
    g.assign(n, std::vector<int>());
    p.assign(n, 0);
    for (int i = 1; i < n; ++i) {
        std::cin >> p[i];
        p[i]--;
        g[p[i]].push_back(i);
    }
    sz.assign(n, 0);
    s.assign(n, 0);
    h.assign(n, -1);
    dfs(0);
    for (int i = 0; i < n; ++i)
        std::cin >> s[i];
    for (int i = 0; i < q; ++i) {
        int v;
        std::cin >> v;
        v--;
        std::cout << h[v] << ' ';
    }
    std::cout << '\n';
}

signed main()
{
    int t = 1;
#ifdef LOCAL
    freopen("stream/inc.txt", "r", stdin);
    freopen("stream/outc.txt", "w", stdout);
    std::cin >> t;
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    for (int i_t = 1; i_t <= t; ++i_t) {
#ifdef LOCAL
    std::cout << "Test case " << i_t << '\n';
#endif
        solve();
    }
    std::cout.flush();
    return 0;
}