QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#706373#8140. Customs Controls 2Yaimsea#WA 0ms10024kbC++201.6kb2024-11-03 10:55:242024-11-03 10:55:25

Judging History

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

  • [2024-11-03 10:55:25]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:10024kb
  • [2024-11-03 10:55:24]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
vector<int> E1[200010],E2[200010],E3[200010];
int n,m,du1[200010],du2[200010],id[200010],f[200010],ans[200010],dp[200010];
int head,tail,q[200010];
int getf(int x)
{
	if(f[x]==x)
		return x;
	f[x]=getf(f[x]);
	return f[x];
}
inline void merge(int x,int y)
{
	int t1=getf(x),t2=getf(y);
	if(t1!=t2)
		f[t2]=t1;
	return;
}
int main()
{
	int i,u,v,las,sum,num,vis,T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d %d",&n,&m);
		for(i=1;i<=m;++i)
		{
			scanf("%d %d",&u,&v);
			E1[u].push_back(v);
			E3[v].push_back(u);
			++du1[v];
		}
		for(i=1;i<=n;++i)
			f[i]=i;
		for(i=1;i<=n;++i)
		{
			u=i,vis=0;
			for(auto v:E3[u])
			{
				if(!vis)
					las=v,vis=1;
				else
				{
					merge(las,v);
					las=v;
				}
			}
		}
		for(i=1;i<=n;++i)
			id[i]=getf(i);
		sum=0;
		for(i=1;i<=n;++i)
		{
			u=i;
			for(auto v:E1[u])
			{
				E2[id[u]].push_back(id[v]);
				++sum,++du2[id[v]];
			}
		}
		head=1,tail=2,q[1]=1,dp[1]=1,num=0;
		while(head<tail)
		{
			u=q[head];
			for(auto v:E2[u])
			{
				--du2[v],++num,dp[v]=max(dp[v],dp[u]+1);
				if(!du2[v])
					q[tail]=v,++tail;
			}
			++head;
		}
		if(num!=sum)
			printf("No\n");
		else
		{
			head=1,tail=2,q[1]=1;
			while(head<tail)
			{
				u=q[head];
				for(auto v:E1[u])
				{
					--du1[v],ans[v]=dp[id[v]]-dp[id[u]];
					if(!du2[v])
						q[tail]=v,++tail;
				}
				++head;
			}
			printf("Yes\n");
			for(i=1;i<=n;++i)
				printf("%d ",ans[i]);
			printf("\n");
		}
		for(i=1;i<=n;++i)
		{
			E1[i].clear(); E2[i].clear(); E3[i].clear();
			du1[i]=du2[i]=0;
		}
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 10024kb

input:

2
3 3
1 2
1 3
2 3
8 9
1 2
1 3
1 4
2 5
3 6
4 7
5 8
6 8
7 8

output:

No
Yes
0 1 3 1 3 1 3 1 

result:

wrong answer Integer parameter [name=w[i]] equals to 0, violates the range [1, 10^9] (test case 2)