QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#438229 | #8544. Colorful Graph 2 | ucup-team045# | WA | 145ms | 3796kb | C++20 | 2.1kb | 2024-06-10 14:18:15 | 2024-06-10 14:18:16 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<set>
#include<cassert>
#include<algorithm>
using namespace std;
using LL = long long;
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int T;
cin >> T;
while(T--){
int n, m;
cin >> n >> m;
vector<vector<int> > g(n);
vector<pair<int, int> > edge(m);
for(int i = 0; i < m; i++){
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
edge[i] = {a, b};
}
for(int i = 0; i < n; i++){
int a = i, b = (i + 1) % n;
g[a].push_back(b);
g[b].push_back(a);
edge.push_back({a, b});
}
vector<int> d(n);
for(auto [a, b] : edge){
d[a] += 1;
d[b] += 1;
}
vector<bool> del(n);
vector<int> v;
for(int i = 0; i < n; i++){
if (d[i] <= 2){
del[i] = true;
v.push_back(i);
}
}
vector<int> order;
while(!v.empty()){
sort(v.begin(), v.end());
order.insert(order.end(), v.begin(), v.end());
vector<int> nv;
for(auto x : v){
for(auto j : g[x]){
if (--d[j] <= 2 and !del[j]){
del[j] = true;
nv.push_back(j);
}
}
}
v.swap(nv);
}
reverse(order.begin(), order.end());
assert(order.size() == n);
set<int> s;
vector<int> color(n);
for(auto x : order){
if (!s.empty()){
auto it = s.lower_bound(x);
if (it == s.end()) it = s.begin();
color[x] = color[*it] ^ 1;
}
s.insert(x);
}
for(auto x : color) cout << (x ? 'R' : 'B');
cout << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3604kb
input:
3 3 0 4 1 1 3 6 3 0 2 2 4 4 0
output:
BRB BRRB BBRRBR
result:
ok ok (3 test cases)
Test #2:
score: 0
Accepted
time: 145ms
memory: 3796kb
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:
BBRRRRBRR BRB BBRRB BRRRBB RBBRRRBBR BRB BBBRBBR RBRBRBB BRRB BBRRBR RRRBRB RBRRRBB BRRBRBBR BRB BRBRBBRR BRRBRBBR BRB BBRBRBBBRB RBBRRRBR BRBRRRBRBB RBRRBBRBBR RBRBBRBRRB BRB BRRRBRB BRBRBB BBRRBRBB BRRB RRBRBRB RBRBBBRBBB BRBBBRB RBBBRRBR BRBRBB BBRRBR BRB BRB RBRBRBRBR BRRRBBR BRRBR RBBBBRRBRB BR...
result:
ok ok (100000 test cases)
Test #3:
score: -100
Wrong Answer
time: 128ms
memory: 3540kb
input:
100000 8 4 5 3 5 1 6 1 3 1 7 4 5 0 4 1 4 0 3 1 4 0 8 1 4 7 3 0 3 0 8 1 1 3 3 0 9 4 6 0 3 0 3 1 5 0 7 0 6 2 4 2 0 4 7 3 0 3 0 4 1 3 5 1 3 0 10 4 6 8 5 2 1 5 5 3 5 1 1 4 3 0 9 3 5 0 8 6 6 0 3 0 5 2 1 3 1 4 9 0 6 1 4 2 8 1 1 3 5 0 8 2 3 1 6 1 5 1 3 0 8 3 3 0 7 4 7 5 7 2 5 3 1 3 10 3 8 0 0 3 8 5 9 4 3 0...
output:
BRBRRBBB BRBRBRR RBRB RBRBRBRB BRB BRB BRRBRBRB BRB BBBRRBRBR BRBRBRB BBRRBR RRRBBRB RBRBB RBRRRBRRBR BRBRB BRB RRBRBRBRB BRB RBBRB BRBRBRBRB RBRRBB BRRBRBRB BRBRB RBBRBRBR RBRBB RBRBRRRB RBBRRBR RBRBBRBRBB BBRBRBRRB BRBRRBRBR RBRBRB RBRBBRB BRB BRRBRBRBRB BRBRBR BRBRBRBRR RBRRB RBBRBBRBRR BBRRB BBR...
result:
wrong answer cycle detected (test case 202)