#include <bits/stdc++.h>
using namespace std;
struct node{
int data;
node *left,*right;
};
int n,m,x,y;
int check[114514];
node *p[114514];
int main()
{
scanf("%d",&n);
node *now,*head = new node;head->data = 0;head->left = head->right = NULL;
now = head; p[0] = head;
head = new node;head->data = 1;head -> right = head->left = now;
now->left = now->right = head;now = head;p[1] = head;
for (int i=2;i<=n;++i){
scanf("%d%d",&x,&y);
now = p[x];
if (y == 1)
now = now->right;
head = new node;
head->data = i;head->left = now->left,head->right = now;
now->left->right = head;
now->left = head;
p[i] = head;
}
/*for (node *i = p[1];i->data != 0;i = i->right)
printf("%d ",i->data);
puts(""); */
scanf("%d",&m);
for (int i=1;i<=m;i++)
scanf("%d",&x),check[x] = 1;
now = p[1];
while (now->data != 0)
{
if (check[now->data]) {
now = now->right;continue;
}
printf("%d ",now->data);
now = now->right;
}
return 0;
}
貌似是插入的地方错了(好像)