QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#386044 | #8544. Colorful Graph 2 | ucup-team1004# | WA | 0ms | 5852kb | C++14 | 636b | 2024-04-11 11:21:28 | 2024-04-11 11:21:29 |
Judging History
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)