QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#386044#8544. Colorful Graph 2ucup-team1004#WA 0ms5852kbC++14636b2024-04-11 11:21:282024-04-11 11:21:29

Judging History

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

  • [2024-04-11 11:21:29]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5852kb
  • [2024-04-11 11:21:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int fa[N],dep[N],n,m,T;
int getfa(int x)
{
	if(x==fa[x]) return x;
	int y=getfa(fa[x]);
	dep[x]+=dep[fa[x]],fa[x]=y;
	return y;
}
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d",&n,&m);
		if(m==0)
		{
			for(int i=1;i<=n;i++)
				putchar("RB"[i&1]);
			putchar('\n');
			continue;
		}
		for(int i=1;i<=n;i++) fa[i]=i,dep[i]=0;
		for(int i=1,x,y;i<=m;i++)
		{
			scanf("%d%d",&x,&y),x++,y++;
			if(getfa(x)!=getfa(y)) fa[x]=fa[y],dep[x]++;
		}
		for(int i=1;i<=n;i++)
			getfa(i),putchar("RB"[dep[i]&1]);
		putchar('\n');
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
3 0
4 1
1 3
6 3
0 2
2 4
4 0

output:

BRB
RBRR
RRBRRR

result:

wrong answer cycle detected (test case 3)