#include<iostream>
#include<vector>
#include<queue>
#include<bits/stdc++.h>
using namespace std;
priority_queue< pair<int,int> ,vector<pair<int,int> > ,greater<pair<int,int> > > tree[112341];
int val[113212];
int a[114414];
int k,n;
void dfs(int p){
while(!tree[p].empty()){
auto y = tree[p].top();
dfs(y.second);
tree[p].pop();
}
if(tree[p].empty()){
cout<<p<<" ";
}
return;
}
int main(){
k = n;
cin>>n;
for(int i=2;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
cin>>val[i];
}
for(int i=2;i<=n;i++){
tree[a[i]].push(make_pair(val[i],i));
}
dfs(1);
return 0;
}