QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#389939 | #8544. Colorful Graph 2 | hos_lyric | WA | 0ms | 3628kb | C++14 | 2.5kb | 2024-04-14 21:24:31 | 2024-04-14 21:24:32 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
int N, M;
vector<int> A, B;
int main() {
for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
scanf("%d%d", &N, &M);
A.resize(M);
B.resize(M);
for (int i = 0; i < M; ++i) {
scanf("%d%d", &A[i], &B[i]);
}
vector<vector<int>> graph(N);
for (int i = 0; i < M; ++i) {
graph[A[i]].push_back(B[i]);
graph[B[i]].push_back(A[i]);
}
queue<int> que;
vector<int> deg(N);
for (int u = 0; u < N; ++u) {
deg[u] = graph[u].size();
if (deg[u] <= 2) {
que.push(u);
}
}
vector<int> us;
for (; que.size(); ) {
const int u = que.front();
que.pop();
us.push_back(u);
for (const int v : graph[u]) {
if (--deg[v] == 2) {
que.push(v);
}
}
}
// cerr<<"us = "<<us<<endl;
assert((int)us.size() == N);
string ans(N, '?');
for (int j = N; --j >= 0; ) {
const int u = us[j];
int cnt[2] = {};
for (const int v : graph[u]) {
if (ans[v] == 'B') ++cnt[0];
if (ans[v] == 'R') ++cnt[1];
}
ans[u] = cnt[0] ? 'R' : 'B';
}
puts(ans.c_str());
}
#ifndef LOCAL
break;
#endif
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3628kb
input:
3 3 0 4 1 1 3 6 3 0 2 2 4 4 0
output:
BBB BRBB RBRBBB
result:
wrong answer cycle detected (test case 1)