Task: | Graph painting |
Sender: | Game of Nolife |
Submission time: | 2016-05-28 12:36:54 +0300 |
Language: | C++ |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.06 s | details |
#2 | ACCEPTED | 0.05 s | details |
#3 | ACCEPTED | 0.15 s | details |
Code
#include <bits/stdc++.h> #define F first #define S second #define X real() #define Y imag() using namespace std; typedef long long ll; typedef long double ld; vector<int> g[101010]; bool r[101010]; int happy[101010]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int tcs; cin>>tcs; for (int tc=0;tc<tcs;tc++) { int n,m; cin>>n>>m; for (int i=0;i<m;i++) { int a,b; cin>>a>>b; g[a].push_back(b); g[b].push_back(a); } for (int i=1;i<=n;i+=2) r[i]=true; set<int> yay; for (int i=1;i<=n;i++) { if (r[i]) { for (auto x : g[i]) { if (r[x]) happy[i]++; else happy[i]--; } } else { for (auto x : g[i]) { if (r[x]) happy[i]--; else happy[i]++; } } if (happy[i]>0) yay.insert(i); } while (!yay.empty()) { int a=*yay.begin(); yay.erase(a); if (r[a]) r[a]=false; else r[a]=true; happy[a]=-happy[a]; if (r[a]) { for (auto x : g[a]) { if (r[x]) { happy[x]++; if (happy[x]==1) yay.insert(x); } else { happy[x]--; if (happy[x]==0) yay.erase(x); } } } else { for (auto x : g[a]) { if (r[x]) { happy[x]--; if (happy[x]==0) yay.erase(x); } else { happy[x]++; if (happy[x]==1) yay.insert(x); } } } } for (int i=1;i<=n;i++) { if (r[i]) cout<<"R "; else cout<<"B "; } cout<<"\n"; for (int i=1;i<=n;i++) { g[i].clear(); happy[i]=0; r[i]=false; } } }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
100 7 1 2 5 8 28 2 7 ... |
correct output |
---|
B R B B B B R R B B R B R B B R R B B B B R R R B B B R B R B B B B R B R R B R ... |
user output |
---|
R B R B R B R R B R B R B R B R B B B B B R R R B R B R B R B R B B B R B R B R ... |
Test 2
Verdict: ACCEPTED
input |
---|
10 38 36 18 28 20 37 22 38 ... |
correct output |
---|
R R B R B R R R R R B B R B R ... |
user output |
---|
R B R R R B R B R B B B R R R ... |
Test 3
Verdict: ACCEPTED
input |
---|
1 100000 200000 89300 98492 33853 56822 92967 99427 ... |
correct output |
---|
R R R R B R R R B B B R B B B ... |
user output |
---|
B B R B B R R B R B B R B B R ... |