1 | #include<bits/stdc++.h> |
2 | using namespace std; |
3 | const int N=1e5+10; |
4 | int n; |
5 | int m; |
6 | int val_i[N]; |
7 | int pre[N]; |
8 | int nxt[N]; |
9 | int pos[N]; |
10 | int head; |
11 | void print(int x) |
12 | { |
13 | cout<<x<<' '; |
14 | if(nxt[x]!=0) |
15 | print(nxt[x]); |
16 | } |
17 | int main() |
18 | { |
19 | cin>>n; |
20 | head=1; |
21 | for(int i=1;i<n;i++) |
22 | { |
23 | int k,p; |
24 | cin>>k>>p; |
25 | if(p==0) |
26 | { |
27 | if(k==head) |
28 | { |
29 | head=i; |
30 | } |
31 | pre[i]=pre[k]; |
32 | nxt[i]=k; |
33 | pre[k]=i; |
34 | } |
35 | else |
36 | { |
37 | nxt[i]=nxt[k]; |
38 | nxt[k]=i; |
39 | pre[i]=k; |
40 | } |
41 | } |
42 | cin>>m; |
43 | while(m--) |
44 | { |
45 | int x; |
46 | cin>>x; |
47 | if(x==head) |
48 | { |
49 | head=nxt[x]; |
50 | } |
51 | pre[nxt[x]]=pre[x]; |
52 | nxt[pre[x]]=nxt[x]; |
53 | pre[x]=0; |
54 | nxt[x]=0; |
55 | } |
56 | print(head); |
57 | return 0; |
58 | } |