QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#405327#8544. Colorful Graph 2maojunWA 1ms5740kbC++20783b2024-05-05 17:29:502024-05-05 17:29:50

Judging History

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

  • [2024-05-05 17:29:50]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5740kb
  • [2024-05-05 17:29:50]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N=2e5+5;
int n,m;
const int E=N+N<<1;
int tot,head[N],to[E],nxt[E];
inline void Add(int u,int v){to[++tot]=v;nxt[tot]=head[u];head[u]=tot;}

bool vis[N],col[N];
inline void solve(){
	tot=0;for(int i=1;i<=n;i++){head[i]=0;vis[i]=false;}
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){Add(i,i%n+1);Add(i%n+1,i);}
	for(int i=1,u,v;i<=m;i++){scanf("%d%d",&u,&v);Add(u,v);Add(v,u);}
	queue<int>q;q.push(1);vis[1]=true;
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=head[u];i;i=nxt[i]){
			int v=to[i];
			if(!vis[v]){col[v]=!col[u];q.push(v);vis[v]=true;}
		}
	}
	for(int i=1;i<=n;i++)putchar(col[i]?'B':'R');putchar(0xa);
}
int main(){
	int T;scanf("%d",&T);
	while(T--)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5740kb

input:

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

output:

RBB
RBBB
RBRRRB

result:

wrong answer cycle detected (test case 2)