QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#405327 | #8544. Colorful Graph 2 | maojun | WA | 1ms | 5740kb | C++20 | 783b | 2024-05-05 17:29:50 | 2024-05-05 17:29:50 |
Judging History
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)