problem
solution
codes
#include<iostream>
using namespace std;
int le[100010], ri[100010], book[100010];
int main(){
int n; cin>>n; ri[0] = 1;
for(int i = 2; i<= n; i++){
int a, b; cin>>a>>b;
if(b == 0){
ri[i] = a;
le[i] = le[a];
ri[le[a]] = i;
le[a] = i;
}else{
le[i] = a;
ri[i] = ri[a];
le[ri[a]] = i;
ri[a] = i;
}
}
int m; cin>>m;
for(int i = 1; i <= m; i++){
int a; cin>>a; book[a] = 1;
}
int cur = 0;
for(int i = 0; i < n; i++){
cur = ri[cur];
if(!book[cur])cout<<cur<<" ";
}
return 0;
}