duilie

· · 个人记录

//P1160 队列安排

include<cstdio>

include<list>

using namespace std ;

const int N = 1e5 + 10 ;

list<int> mylist ; list<int>::iterator ait[N] ;

int n , m ;

int main() { scanf("%d" , &n) ;

list<int>::iterator it ;

mylist.push_back(1) ;
ait[1] = mylist.begin() ;

for(int i = 2 ; i <= n ; ++ i)
{
    int x , y ;

    scanf("%d%d" , &x , &y) ;

    if(y)
    {
        it = ait[x] ;
        mylist.insert(++ it , i) ;
        ait[i] = -- it ;
    }
    else 
    {
        it = ait[x] ;
        mylist.insert(it , i) ;
        ait[i] = -- it ;
    }
}

scanf("%d" , &m) ;

while(m --)
{
    int x ;

    scanf("%d" , &x) ;

    if(ait[x] != mylist.end())
        mylist.erase(ait[x]) ;

    ait[x] = mylist.end() ;     
}

for(it = mylist.begin() ; it != mylist.end() ; ++ it )
    printf("%d " , *it) ;

return 0 ;  

}