QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#390806 | #8544. Colorful Graph 2 | Core_65536 | WA | 100ms | 3688kb | C++17 | 1.3kb | 2024-04-15 22:14:37 | 2024-04-15 22:14:38 |
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;
//cout<<ThisDes<<' ';
ans.push_back({ThisDes,color});
q.push(ThisDes);
}
}
color = !color;
q.pop();
}
//cout<<endl;
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: 100
Accepted
time: 0ms
memory: 3680kb
input:
3 3 0 4 1 1 3 6 3 0 2 2 4 4 0
output:
RBB RBRB RBBRBB
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 100ms
memory: 3688kb
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:
RBBRBBBBB RBB RBBBB RBRRRB RBRRBRRBB RBB RBRBBBB RBRRRBB RBRB RBBRBB RBRBBB RBRRRBB RBRRRBBB RBB RBBBBBBB RBRRRBBB RBB RBBBBBBBBB RBRRBBRB RBRBBBBBBB RBRRRRRRRB RBBBBRBBBB RBB RBRRRBB RBRRRB RBBRRRBB RBRB RBBBBBB RBRRRRRRBB RBRRBBB RBRRRBRB RBRRRB RBBRBB RBB RBB RBRRRRRRB RBRRBBB RBRBB RBRRBRBRBB RB...
result:
wrong answer cycle detected (test case 1)