QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#572656 | #8544. Colorful Graph 2 | wangjingheng | WA | 0ms | 3580kb | C++14 | 835b | 2024-09-18 15:50:44 | 2024-09-18 15:50:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
void solve(){
int n,m;cin>>n>>m;
vector<int> c(n+1);
vector<pair<int,pair<int,int> > > g;
for(int i=1;i<=m;i++){
int u,v;cin>>u>>v;
int x=(u-v)%n;
x=(x+n)%n;
int y=(v-u)%n;
y=(y+n)%n;
if(x<=y){
g.push_back({x,{v,u}});
}
}
sort(g.begin(),g.end());
for(auto [_,e]:g){
auto [u,v]=e;
if(c[u]&&c[v]) continue;
if(c[u]){
c[v]=3-c[u];
}
else if(c[v]){
c[u]=3-c[v];
}
else{
c[u]=1,c[v]=2;
}
}
int cc=0;
for(int i=0;i<n;i++){
if(c[i]==1){
cout<<"B";
}
else if(c[i]==2){
cout<<"R";
}
else{
if(!cc) cout<<"B";
else cout<<"R";
cc=1-cc;
}
}
cout<<"\n";
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int T;cin>>T;
while(T--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3580kb
input:
3 3 0 4 1 1 3 6 3 0 2 2 4 4 0
output:
BRB BRRB BRBRBR
result:
wrong answer cycle detected (test case 3)