QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#388290 | #8544. Colorful Graph 2 | ucup-team1055# | WA | 145ms | 3876kb | C++20 | 1.9kb | 2024-04-13 14:31:35 | 2024-04-13 14:31:37 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i = int(s); i < int(n); i++)
#define rrep(i,s,n) for(int i = int(n) - 1; i >= int(s); i--)
#define all(v) (v).begin(),(v).end()
using ll = long long;
using ld = long double;
using ull = unsigned long long;
bool chmin(auto &a, auto b) {
if(a <= b) return false;
a = b;
return true;
}
bool chmax(auto &a, auto b) {
if(a >= b) return false;
a = b;
return true;
}
using namespace std;
void solve(){
int n, m; cin >> n >> m;
vector<set<int>> g(n);
rep(i,0,m){
int u, v; cin >> u >> v;
g[u].insert(v);
g[v].insert(u);
}
auto deg = [&](int v){
return g[v].size();
};
vector<int> ans(n,-1);
auto dfs = [&](auto sfs, vector<int> del) -> void {
vector<int> deg2;
for (int v : del){
// deg(v) == 2
for (int u : g[v]){
g[u].erase(v);
if (deg(u) == 2){
deg2.emplace_back(u);
}
}
}
if (deg2.empty()){
// degl.size() >= 2
int x = 0;
for (int v : del){
ans[v] = x;
x ^= 1;
}
return ;
}
sfs(sfs,deg2);
for (int v : del){
int u = *g[v].begin();
ans[v] = ans[u]^1;
}
};
vector<int> deg2;
rep(i,0,n){
g[i].insert(i == n-1 ? 0 : i+1);
g[i].insert(i == 0 ? n-1 : i-1);
if (deg(i) == 2){
deg2.emplace_back(i);
}
}
dfs(dfs,deg2);
string sans = "";
rep(i,0,n) sans += (ans[i] == 0 ? 'B' : 'R');
cout << sans << '\n';
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int t; cin >> t;
while (t--){
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3592kb
input:
3 3 0 4 1 1 3 6 3 0 2 2 4 4 0
output:
BRB RBRR RBBRBB
result:
ok ok (3 test cases)
Test #2:
score: 0
Accepted
time: 145ms
memory: 3612kb
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:
RBBRBRRBB BRB BRRBB RBRBRR BRBBRBBRB BRB RBRBBRB BRBBBBR RBRR RBBRBB BRBRBR BRBRBBR RBRRRRBB BRB RBBBBRBB RBRRRRBB BRB RBBRBRBRRR RBRRBRBR RBRBRBRRRR BRBRBRBRRB BRRRBRRBRB BRB RBRBRBR RBRRRR RBBRRRRR RBRR RBBRBBB BRBRBRRRRR RBRBRBB BRBRBRBB RBRRRR RBBRBB BRB BRB RBRRRBBBR RBRBBRB RBRBB RBRBRRBRRB RB...
result:
ok ok (100000 test cases)
Test #3:
score: -100
Wrong Answer
time: 119ms
memory: 3876kb
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:
RBRRBRRB RBRRBBB BRBR RRRBRBRB BRB BRB RBRRBRRB BRB BRBRBRRBR BRBRBRB BRRBBR BRBRRBR BRBRR BRBRBRBRRR RBRBR BRB BRRRBRRBR BRB BRBBB BRBRBRBRB RRBRRB RBRRBRRB BRBRB RBRRBRBR BRBRR RRRBRBRB RBRRBBR BRRBRRBBRR BRBRRBRBB BRBRBBBBR BRBRBR BRBRBBR BRB RBRRRRBRBB RBRRRB RBRBRRBBR RBRBB RRRRRRRBRB BRRBB BRR...
result:
wrong answer cycle detected (test case 38)