样例能过全RE求助
查看原帖
样例能过全RE求助
1199534
ycy1124楼主2024/4/6 11:18
#include<bits/stdc++.h>
using namespace std;
struct node{
	int last,next;
	bool pd=1;
}xs[100001];
void read(int &x)
{
	int f=1;
	x=0;
	char ch=getchar();
	if(ch<'0'||ch>'9')
	{
		f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x*=10;
		x+=ch-'0';
		ch=getchar();
	}
	x*=f;
 } 
int main()
{
	int n,t=1;
	xs[1].next=0;
	xs[1].last=0;
	read(n);
	for(int i=2;i<=n;i++)
	{
		int k,p;
		read(k);
		read(p);
		if(k==t&&p==0)
		{
			t=i;
		}
		if(p==0)
		{
			if(xs[k].last==0)
			{
				xs[k].last=p;
				xs[i].next=k;
			}
			else
			{
				xs[i].last=xs[k].last;
				xs[xs[k].last].next=i;
				xs[i].next=k;
				xs[k].last=i;
			}
		}
		else
		{
			if(xs[k].next==0)
			{
				xs[k].next=p;
				xs[i].last=k;
			}
			else
			{
				xs[i].next=xs[k].next;
				xs[xs[k].next].last=i;
				xs[i].last=k;
				xs[k].next=i;
			}
		}
	}
	int m;
	read(m);
	for(int i=1;i<=m;i++)
	{
		int x;
		read(x);
		if(x==t)
		{
			t=xs[x].next;
		}
		if(xs[x].pd)
		{
			xs[xs[x].last].next=xs[x].next;
			xs[xs[x].next].last=xs[x].last;
			xs[x].pd=0;
		}
	}
	while(t!=0)
	{
		printf("%d ",t);
		t=xs[t].next;
	}
	return 0;
}

2024/4/6 11:18
加载中...