QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#390801 | #8544. Colorful Graph 2 | Core_65536 | WA | 0ms | 3528kb | C++17 | 1.2kb | 2024-04-15 22:08:03 | 2024-04-15 22:08:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void solve()
{
int n,m; cin>>n>>m;
vector<vector<int>> v(n);
for(int i=0;i<n;i++)
v[i].push_back((i+1)%n), v[i].push_back((i-1+n)%n);
for(int i=0;i<m;i++)
{
int x,y; cin>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
//Start BFS
vector<int> vis(n+5,0);
queue<int> q;
q.push(0);
vis[0]=1;
//BFS
vector<pair<int,bool>> ans; ans.push_back({0,1});
bool color=0; //0:Black 1:Red
while(!q.empty()){
int Qfro = q.front();
for(int i=0;i<v[Qfro].size();i++){
int ThisDes = v[Qfro][i];
if(!vis[ThisDes]){
vis[ThisDes]=1;
ans.push_back({ThisDes,color});
q.push(ThisDes);
color = !color;
}
}
q.pop();
}
sort(ans.begin(),ans.end());
for(auto i:ans){
if(i.second) cout<<'R';
else cout<<'B';
}
cout<<endl;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int T=1; cin>>T;
while(T--) solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3528kb
input:
3 3 0 4 1 1 3 6 3 0 2 2 4 4 0
output:
RBR RBBR RBBBRR
result:
wrong answer cycle detected (test case 3)