Note
Code
#include<bits/stdc++.h>
using namespace std;
int num[110],ind=0;
struct Node{
int data;
int left,right;
}tree[110];
void inorder(int root){
if(root==-1) return ;
inorder(tree[root].left);
tree[root].data=num[ind++];
inorder(tree[root].right);
}
void level_order(int root){
int cnt=0;
queue<int> q;
q.push(root);
while(!q.empty()){
int inx=q.front();
q.pop();
if(cnt!=0) printf(" ");
printf("%d",tree[inx].data);
cnt++;
if(tree[inx].left!=-1) q.push(tree[inx].left);
if(tree[inx].right!=-1) q.push(tree[inx].right);
}
}
int main(){
#ifndef ONLINE_JUDGE
freopen("data.txt","r",stdin);
#endif
int n,l,r;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d %d",&l,&r);
tree[i].left=l;
tree[i].right=r;
}
for(int i=0;i<n;i++)
scanf("%d",&num[i]);
sort(num,num+n);
inorder(0);
level_order(0);
return 0;
}