#include<bits/stdc++.h> 
using namespace std;
bool vis[1000003];
list<int> stus;
list<int>::iterator pos[1000003];//用来存放每一项的迭代器 这样遍历链表的时间能从O(n)变成O(1)
int main(){
    int n;
    scanf("%d",&n);
    stus.push_front(1);//插入1到头部 
    pos[1] = stus.begin();//放入迭代器的开始  相当于存入的位置在哪里
    for(int i = 2;i <= n;i++){
        int k,p;
        scanf("%d %d",&k,&p);
        if(p==0){//在左边
            pos[i] = stus.insert(pos[k],i);//插入左边返回一个迭代器 
        } 
        else{
            list<int>::iterator it = pos[k];//取出第k个元素迭代器的位置
            it++;
            pos[i] = stus.insert(it,i);    
        }
    }
    int m = 0;
    scanf("%d",&m);
    while(m--){
        int x = 0;
        scanf("%d",&x);
        if(!vis[x]){
           vis[x]=true;//标记他被删过了
           stus.erase(pos[x]);//传入他的迭代器     
        } 
            
    }
    for(list<int>::iterator it = stus.begin();it!=stus.end();it++){
        printf("%d ",*it);
    }
    printf("\n"); 
    

    return 0; 
} 

 

相关文章:

  • 2021-10-16
  • 2022-03-03
  • 2021-05-25
  • 2021-11-29
  • 2021-12-31
  • 2022-12-23
  • 2022-12-23
  • 2021-10-29
猜你喜欢
  • 2021-09-09
  • 2021-09-22
  • 2021-05-19
  • 2021-07-31
  • 2021-08-04
  • 2021-12-05
相关资源
相似解决方案