QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#706387#8140. Customs Controls 2Yaimsea#RE 2ms10088kbC++201.7kb2024-11-03 11:00:442024-11-03 11:00:46

Judging History

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

  • [2024-11-03 11:00:46]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:10088kb
  • [2024-11-03 11:00:44]
  • 提交

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,ans[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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 10008kb

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
1 1 3 1 3 1 3 1 

result:

ok ok (2 test cases)

Test #2:

score: 0
Accepted
time: 2ms
memory: 10088kb

input:

2
11 16
1 2
1 3
1 4
1 5
2 6
4 6
3 7
4 7
5 8
6 8
2 9
3 9
7 10
8 10
9 11
10 11
8 10
1 2
1 3
2 4
3 5
3 6
4 6
2 7
5 7
6 8
7 8

output:

Yes
1 1 1 1 2 1 2 1 3 1 1 
No

result:

ok ok (2 test cases)

Test #3:

score: 0
Accepted
time: 2ms
memory: 7984kb

input:

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

output:

No

result:

ok ok (1 test case)

Test #4:

score: 0
Accepted
time: 0ms
memory: 10076kb

input:

1
11 16
1 2
1 3
1 4
1 5
2 6
4 6
3 7
4 7
5 8
6 8
2 9
3 9
7 10
8 10
9 11
10 11

output:

Yes
1 1 1 1 2 1 2 1 3 1 1 

result:

ok ok (1 test case)

Test #5:

score: 0
Accepted
time: 0ms
memory: 7948kb

input:

1
3 3
1 2
1 3
2 3

output:

No

result:

ok ok (1 test case)

Test #6:

score: 0
Accepted
time: 2ms
memory: 7960kb

input:

1
15 24
1 3
1 7
1 6
1 12
3 11
3 5
3 13
3 14
3 8
7 11
7 13
7 14
11 2
11 10
6 9
5 9
13 9
14 4
8 4
2 4
10 4
9 4
12 15
4 15

output:

Yes
1 1 1 1 1 2 1 2 1 1 1 4 1 2 1 

result:

ok ok (1 test case)

Test #7:

score: 0
Accepted
time: 2ms
memory: 10020kb

input:

10
20 40
1 8
1 11
1 19
8 7
8 16
8 15
8 14
8 4
8 17
11 5
11 6
11 2
11 3
7 6
7 2
7 3
16 9
16 12
15 9
15 12
14 9
4 18
4 10
5 13
5 10
6 18
6 10
2 13
2 18
3 18
3 10
9 13
9 10
12 13
12 10
19 20
17 20
13 20
18 20
10 20
20 30
8 19
19 12
5 12
5 10
10 4
18 4
18 14
14 6
15 6
15 7
7 3
17 3
17 2
2 16
9 16
9 11
1...

output:

Yes
1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 3 1 4 1 
No
Yes
1 1 1 7 7 1 2 1 5 2 6 3 7 2 5 1 1 1 4 1 
Yes
1 3 8 4 2 1 1 10 8 6 1 1 1 1 2 1 2 2 7 1 
Yes
1 5 1 1 1 1 3 10 8 10 12 1 8 2 4 5 3 8 3 1 
Yes
1 1 1 8 3 1 1 8 8 9 1 1 10 11 1 10 2 8 8 3 
Yes
1 12 1 1 6 6 11 1 2 9 12 1 1 13 1 2 15 1 5 1 
No
Yes
1 13 15 ...

result:

ok ok (10 test cases)

Test #8:

score: -100
Runtime Error

input:

10
1919 3195
1888 1186
1186 519
1514 519
1514 859
859 1634
977 1634
977 185
185 1250
1103 1250
1103 463
463 1683
426 1683
426 1728
1728 1402
1612 1402
1612 1789
1789 857
586 857
586 1669
1669 1376
1833 1376
1833 1076
1076 749
733 749
733 551
551 217
1717 217
1717 862
862 319
96 319
96 479
479 1381
1...

output:


result: