QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#660451 | #8544. Colorful Graph 2 | hjxddl# | RE | 0ms | 0kb | C++20 | 1.2kb | 2024-10-20 11:17:27 | 2024-10-20 11:17:28 |
answer
// Coded by hjxddl
#include <bits/stdc++.h>
#define ll long long
#define db double
const int N = 2e5 + 5;
int n, m;
void solve() {
std::cin >> n >> m;
std::vector<std::vector<int>> e(n + 5);
std::vector<int> col(n + 5);
for (int i = 0; i < n - 1; i++) {
e[i].push_back(i + 1);
e[i + 1].push_back(i);
}
e[n - 1].push_back(0);
e[0].push_back(n - 1);
for (int i = 1; i <= m; i++) {
int u, v;
std::cin >> u >> v;
e[u].push_back(v);
e[v].push_back(u);
}
std::queue<std::pair<int, int>> q;
q.push({0, 2});
while (q.size()) {
auto [x, z] = q.front();
q.pop();
if (col[x]) continue;
col[x] = z;
for (int y : e[x]) {
if (col[y]) continue;
q.push({y, z ^ 1});
}
}
for (int i = 0; i < n; i++) {
if (col[i] == 2)
std::cout << "B";
else
std::cout << "R";
}
std::cout << '\n';
}
int main() {
std::ios::sync_with_stdio(0);
std::cin.tie(0), std::cout.tie(0);
int t = 1;
std::cin >> t;
while (t--) {
solve();
}
std::cout << std::flush;
system("pause");
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Dangerous Syscalls
input:
3 3 0 4 1 1 3 6 3 0 2 2 4 4 0
output:
BRR BRBR BRRBRR