QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#601956 | #8544. Colorful Graph 2 | ucup-team4153 | WA | 53ms | 8440kb | C++17 | 1.5kb | 2024-09-30 16:45:14 | 2024-09-30 16:45:15 |
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<n;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: 100
Accepted
time: 0ms
memory: 8440kb
input:
3 3 0 4 1 1 3 6 3 0 2 2 4 4 0
output:
BRR RBBR BBRRBR
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 53ms
memory: 8312kb
input:
100000 9 6 2 0 4 6 3 6 0 6 0 7 2 6 3 0 5 2 2 4 2 0 6 3 1 5 4 1 2 4 9 6 3 1 6 4 8 1 3 6 1 6 8 6 3 0 7 4 3 0 4 0 6 4 3 1 7 4 5 1 5 0 3 1 1 4 4 1 1 3 6 3 2 4 4 0 2 0 6 3 3 0 1 3 5 3 7 4 0 5 2 5 5 1 3 5 8 5 4 1 5 1 5 0 1 3 5 7 3 0 8 5 0 2 4 6 0 6 0 3 4 0 8 5 5 1 1 4 5 0 3 1 5 7 3 0 10 7 0 2 9 2 5 8 3 9 ...
output:
BBRRRRBRR BRR BBRRB RBBBRR RBBRRRBBR BRR BBBRRRB BBBRRRR RBBR BRBBRR BBBRRB BBBBBRR BBBRRRRB BRR BBRRBBRR BBBRRRRB BRR BBRRRRRRBB RBRBBBRR RBBBBBBRRR RBBBBBRRRR BBRRBBRRRB BRR RBRRBBR RBBRRR BBRRBBBB RBBR BBRRRBB RBBBBBRRRR RBBBBRR RBRRBBRR RBBRRR BBRRBR BRR BRR RBBRRRBBR BBBBRRB BBBRR RBBBBRRRBB BB...
result:
wrong answer cycle detected (test case 47)