//
// na 1156.cpp
// Competitive Programming
//
// Created by m2 on 2024/11/13.
//
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#ifdef MAC_OS_VERSION_11_0
const int maxn = 15;
#else
const int maxn = 1e5 + 5;
#endif
int n, v[maxn], r[maxn], p[maxn];
vector<int> ch[maxn];
void dfs1(int idx){
r[idx] = v[idx];
for(int c: ch[idx]){
dfs1(c);
r[idx] = min(r[idx], r[c]);
}
}
inline bool cmpr(int a, int b){
return r[a] < r[b];
}
void sol(int idx){
sort(ch[idx].begin(), ch[idx].end(), cmpr);
for(int c: ch[idx])
sol(c);
cout << idx << ' ';
}
int main(){
cin.tie(0)->sync_with_stdio(false);
cin >> n;
for(int i = 2; i <= n; ++i){
cin >> p[i];
ch[p[i]].push_back(i);
}
for(int i = 1; i <= n; ++i)
cin >> v[i];
dfs1(1);
sol(1);
cout << endl;
return 0;
}