#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn];
int fa[maxn];
vector<int> G[maxn];
int r[maxn];
struct Point{
int v, w;
};
bool operator > (const Point &a, const Point &b) {
return a.w > b.w;
}
priority_queue<Point, vector<Point>, greater<Point> > que[maxn];
int n;
void init(int u) {
r[u] = a[u];
for (int v: G[u]) {
init(v);
r[u] = min(r[u], r[v]);
que[u].push({v, r[v]});
}
}
int vis[maxn];
int dfs(int u) {
if (que[u].size() == 0) {
vis[u] = 1;
return u;
}
int res = dfs(que[u].top().v);
if (vis[que[u].top().v]) {
que[u].pop();
} else {
auto tmp = que[u].top();
que[u].pop();
que[u].push({tmp.v, min(a[tmp.v], tmp.w)});
}
return res;
}
int main() {
cin >> n;
for (int i = 2; i <= n; i++) {
cin >> fa[i];
G[fa[i]].push_back(i);
}
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
init(1);
// for (int i = 1; i <= n; i++) {
// cout << i << " " << que[i].size() << endl;
// }
for (int i = 1; i <= n; i++) {
cout << dfs(1) << " \n"[i==n];
}
}
/*
4
1 2 2
1 3 2 4
*/