QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#530408 | #8544. Colorful Graph 2 | chenxinyang2006 | WA | 146ms | 15884kb | C++20 | 2.1kb | 2024-08-24 16:14:42 | 2024-08-24 16:14:43 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
/*ll power(ll p,int k = mod - 2){
ll ans = 1;
while(k){
if(k % 2 == 1) ans = ans * p % mod;
p = p * p % mod;
k /= 2;
}
return ans;
}*/
int T,n,m;
set <int> G[200005];
void add(int u,int v){
G[u].insert(v);G[v].insert(u);
}
void del(int u,int v){
assert(G[u].count(v));
G[u].erase(v);G[v].erase(u);
}
int a[200005],adj[200005][2],ans[200005];
vector <int> ord,Q;
void solve(){
scanf("%d%d",&n,&m);
rep(u,1,n){
G[u].clear();
adj[u][0] = adj[u][1] = 0;
}
rep(i,1,n - 1) add(i,i + 1);
add(1,n);
rep(i,1,m){
int u,v;
scanf("%d%d",&u,&v);
u++;v++;
add(u,v);
}
ord.clear();Q.clear();
rep(u,1,n) if(SZ(G[u]) <= 2) Q.eb(u);
while(!Q.empty()){
int u = Q.back();
Q.pop_back();
ord.eb(u);
for(int v:G[u]){
if(!adj[u][0]) adj[u][0] = v;
else if(!adj[u][1]) adj[u][1] = v;
else assert(0);
}
if(adj[u][0]) del(u,adj[u][0]);
if(adj[u][1]) del(u,adj[u][1]);
if(adj[u][0] && adj[u][1]) add(adj[u][0],adj[u][1]);
}
while(!ord.empty()){
int u = ord.back();
ord.pop_back();
ans[u] = 0;
if(!ans[adj[u][0]] || !ans[adj[u][1]]) ans[u] = 1;
}
rep(u,1,n){
if(!ans[u]) printf("B");
else printf("R");
}
printf("\n");
}
int main(){
// freopen("test.in","r",stdin);
scanf("%d",&T);
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 15608kb
input:
3 3 0 4 1 1 3 6 3 0 2 2 4 4 0
output:
RRB RRRB RBRRBR
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 146ms
memory: 15884kb
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:
BRBBBRBBR RRB RRBRB BRBRBR BRBRBRBRR RRB RRBRBRB RRBRBRB BRBR BRBRBR BRBRBR BRBRBRR BRBRBRBR RRB RRBRBRBR RRBRBRBR RRB RRBRBRBRRB BRBRBRBR RRBRBRBRRB RRBRBRBRRB RRBRBRBRRB RRB RRBRBRB BRBRBR BRBRBRBR BRBR BRBRBRB RRBRBRBRRB RRBRBRB BRBRBRBR BRBRBR BRBRBR RRB RRB BRBRBRBRR BRBRBRB BRBRR RRBRBRBRRB RR...
result:
wrong answer cycle detected (test case 1)