QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#601953 | #8544. Colorful Graph 2 | ucup-team4153 | WA | 2ms | 8448kb | C++17 | 1.5kb | 2024-09-30 16:42:44 | 2024-09-30 16:42:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
bool vis[N];
char res[N];
vector<int>E[N];
void dfs(int x){
vis[x]=true;
for(auto v:E[x]){
if(res[v]==0){
if(res[x]=='B'){
res[v]='R';
}else{
res[v]='B';
}
dfs(v);
}
}
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t;cin>>t;
while(t--){
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++)vis[i]=false,E[i].clear(),res[i]=0;
for(int i=0;i<m;i++){
int u,v;cin>>u>>v;
E[u].push_back(v);
E[v].push_back(u);
}
for(int i=0;i<m;i++){
if(res[i]==0 && !E[i].empty()){
res[i]='B';
dfs(i);
}
}
vector<int>vec;
for(int i=0;i<n;i++){
if(vis[i]){
vec.push_back(i);
}
}
if(vec.empty()){
res[0]='B';
for(int i=1;i<n;i++)res[i]='R';
}else{
for(int i=0;i<n;i++){
if(vis[i])continue;
if(vis[(i+1)%n]){
if(res[(i+1)%n]=='B')res[i]='R';
else res[i]='B';
}else{
res[i]='B';
}
}
}
for(int i=0;i<n;i++)cout<<res[i];
cout<<'\n';
}
return 0;
}
/*
4 2 7
1 2 0
2 3 0
3 4 0
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 8448kb
input:
3 3 0 4 1 1 3 6 3 0 2 2 4 4 0
output:
BRR BRRR BBRRBR
result:
wrong answer cycle detected (test case 2)