QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#398604 | #8544. Colorful Graph 2 | gqf123 | RE | 0ms | 0kb | C++20 | 1.0kb | 2024-04-25 15:37:45 | 2024-04-25 15:37:48 |
answer
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
using namespace std;
vector<int>to[200000];
inline void solve() {
int n, m;
cin >> n >> m;
string s(n, ' ');
for (int i = 0; i ^ n; ++i) {
to[i].clear();
}
for (int i = 0; i ^ m; ++i) {
int u, v;
cin >> u >> v;
--u, --v;
to[u].emplace_back(v);
to[v].emplace_back(u);
}
for (int i = 0; i ^ n; ++i) {
to[i].emplace_back((i + 1) % n);
to[(i + 1) % n].emplace_back(i);
}
queue<int>q;
q.emplace(0);
s[0] = 'B';
for (; q.size();) {
int u = q.front();
q.pop();
for (const auto& v : to[u]) {
if (s[v] != ' ') {
continue;
}
if (s[u] == 'B') {
s[v] = 'R';
}
else {
s[v] = 'B';
}
q.emplace(v);
}
}
cout << s << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
for (; t--;) {
solve();
}
}
/*
6 7
1 2
1 3
2 4
3 5
2 6
2 4 1
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
6 1 2 6 4 3 5
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 3 0 4 1 1 3 6 3 0 2 2 4 4 0