QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#419024 | #8544. Colorful Graph 2 | tarjen# | WA | 1ms | 3528kb | C++20 | 1.1kb | 2024-05-23 17:03:23 | 2024-05-23 17:03:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
string solve()
{
int n,m;
cin>>n>>m;
set<pair<int,int>> s;
auto addedge =[&](int x,int y){
s.insert({x,y});
s.insert({y,x});
};
auto query = [&](int x,int y){
if(s.find({x,y})!=s.end())return true;
if(s.find({y,x})!=s.end())return true;
return false;
};
while(m--){
int x,y;cin>>x>>y;
addedge(x,y);
}
auto pre = [&](int x){
return (x+n-1)%n;
};
auto nxt = [&](int x){
return (x+1)%n;
};
vector<int> ans(n,0);
int l=0,r=1;
ans[r]=1;
while((r-l+n)%n!=n-1){
if(query(pre(l),r)){
ans[pre(l)]=ans[l]^1;
l=pre(l);
}
else{
ans[nxt(r)]=ans[r]^1;
r=nxt(r);
}
}
string st(n,'0');
for(int i=0;i<n;i++){
st[i]=ans[i]?'B':'R';
}
return st;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T;cin>>T;while(T--)cout<<solve()<<"\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3528kb
input:
3 3 0 4 1 1 3 6 3 0 2 2 4 4 0
output:
RBR RBRB RBRBRB
result:
wrong answer cycle detected (test case 3)