QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#695444#7738. Equivalent Rewritingsix_sspWA 0ms4108kbC++231.3kb2024-10-31 20:02:592024-10-31 20:03:02

Judging History

你现在查看的是最新测评结果

  • [2024-10-31 20:03:02]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4108kb
  • [2024-10-31 20:02:59]
  • 提交

answer

#include<iostream>
#include<queue>
#include<cstdio>
using namespace std;
priority_queue<int > q;
struct node{
	int to,nxt;
}e[2000006];
int cnt,head[100005];
void add(int x,int y)
{
	e[++cnt].to=y;
	e[cnt].nxt=head[x];
	head[x]=cnt;
}
int bu[100005],rd[100005];
int vis[100005],cha[100005];
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	  {
	  	int p;
	  	cin>>p;
	  	for(int j=1;j<=p;j++)
	  	  {
	  	  	cin>>cha[j];
	  	  	if(bu[cha[j]]==0) 
	  	  	  bu[cha[j]]=i;
	  	  	else if((vis[cha[j]]==0) && (bu[cha[j]]!=0))
	  	  	{
	  	  		 add(bu[cha[j]],i);
	  	  		 rd[i]++;
	  	  		 bu[cha[j]]=i;
	  	  		 vis[cha[j]]=1;
			}
		  }
		  for(int j=1;j<=p;j++)
		    vis[cha[j]]=0;
	  }
	//for(int i=1;i<=n;i++)
	 // cout<<rd[i]<<" ";
	int pd=0;
	for(int i=1;i<=n;i++)
	  if(rd[i]==0)
	    q.push(i);
	int ans[100005],cnt=0;
	while(!q.empty())
	{
		int x=q.top();
		q.pop();
		ans[++cnt]=x;
		if(cnt!=x) pd=1;
		for(int i=head[x];i;i=e[i].nxt)
		  {
		  	int y=e[i].to;
		  	rd[y]--;
		  	if(rd[y]==0)
		  	  q.push(y);
		  }
	}
	if(pd==0) cout<<"No";
	if(pd==1)
	{
		cout<<"Yes"<<endl;
		for(int i=1;i<=cnt;i++)
		  cout<<ans[i]<<" ";
   }
	cout<<endl;
	for(int i=1;i<=n;i++)
	  bu[i]=rd[i]=0;
	cnt=0;
   }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4040kb

input:

3
3 6
3 3 1 5
2 5 3
2 2 6
2 3
3 1 3 2
2 3 1
1 3
2 2 1

output:

Yes
3 1 2 
No
No

result:

ok OK. (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 4108kb

input:

1
10 5
2 2 4
4 1 3 4 2
1 2
3 2 1 4
4 5 2 4 3
3 2 5 4
3 5 4 2
3 1 3 2
5 1 4 2 3 5
1 4

output:

No

result:

wrong answer jury found an answer but participant did not (test case 1)