20pts 3RE 1TLE求救
查看原帖
20pts 3RE 1TLE求救
232205
little_kongbai楼主2021/7/12 19:45

RT

	#include<bits/stdc++.h>
	using namespace std;
	int n,k,p,m;
	const int maxn=1e5+5;
	struct node{
		int c;
		node *last=NULL,*next=NULL;
	}*t,*first,*x;
	int main(){
		scanf("%d",&n);
		first=new node;
		first->c=1;
		for(int i=2;i<=n;i++){
			scanf("%d%d",&k,&p);
			t=new node;
			t->c=i;
			x=first;
			while(x->c!=k)x=x->next;
			if(p){
				t->next=x->next;
				if(x->next!=NULL)x->next->last=t;
				t->last=x;
				x->next=t;
			}
			else{
				if(k==first->c){
					first=t;
					t->last=NULL;
				}
				else{
					t->last=x->last;
					node *ls;ls=x->last;
					//cout<<x->last<<endl;
					if(ls!=NULL){
						ls->next=t;
					}
					x->last=t;
				}
				t->next=x;
			}
			//cout<<t->last<<" last"<<endl;
			//cout<<i<<" "<<t<<" "<<t->next<<" "<<x<<endl;
		}
		t=first;
		//while(t!=NULL){cout<<t->c<<" ";t=t->next;}
		scanf("%d",&m);
		for(int i=1;i<=m;i++){
			scanf("%d",&k);
			x=first;
			while(x->c!=k&&x->next!=NULL)x=x->next;
			if(x->c==k){
				if(x->last!=NULL)x->last->next=x->next;
				if(x->next!=NULL)x->next->last=x->last;
			
			}
		}
		x=first;
		do{
			printf("%d ",x->c);
			x=x->next;
		}while(x!=NULL);
		return 0;
	}
2021/7/12 19:45
加载中...