大佬,求助,第二个点re,345TLE
查看原帖
大佬,求助,第二个点re,345TLE
677969
Tom336853楼主2022/7/11 11:36
#include<iostream>
using namespace std;
 
typedef struct qnode{
	int n;
	qnode *next;
}qnode;
typedef struct queue{
	qnode *first;
	
}queue;
void inqueue(queue &q,int i,int m,int l){     	
	if(l==0){			 
		qnode *p=q.first;
		for(int j=0;p->next->n!=m;j++){
			p=p->next;
		}
		qnode *x=new qnode;
		x->n=i;
		x->next=p->next;
		p->next=x;
	}
	else {
		qnode *p=q.first;
		for(int j=0;p->n!=m;j++){
			p=p->next;
		}
		qnode *x=new qnode;
		x->n=i;
		x->next=p->next;
		p->next=x;
	}
	}
void outqueue(queue &q,int m){
	qnode *p=q.first;
	for(int j=0;p->next->n!=m;j++){
		p=p->next;
	}
	qnode *x=p->next;
	p->next=x->next;
	delete(x);
}
int main(){            
	queue q;           
	qnode a;             
	a.n=0;
	q.first=&a;
	qnode b;
	b.n=1;
	a.next=&b;
	b.next=NULL;
	int n;
	cin>> n;
	if(n==1){
		cout<<1<<endl;
		return 0;
	}
	if(n<=0)return 0;
	for(int i = 2; i <= n; i++ ){
		int r,s;
		cin>>r>>s;
		inqueue(q,i,r,s);
	}
	int m;
	int s[100000]={0};
	cin>>m;
	for(int i=0;i<m;i++){
		int r;
		cin>>r;
		if(s[r]==0){
			outqueue(q,r);
		}
		else continue;
		s[r]=1;
	}
		q.first=q.first->next;
	for(int i=0;q.first!=NULL;i++){
		cout<<q.first->n<<" ";
		q.first=q.first->next;
	}
	cout<<endl;
	return 0;
}
2022/7/11 11:36
加载中...