HIIT Open 2016

 Start: 2016-05-28 11:00:00 End: 2016-05-28 16:00:00

CSES - HIIT Open 2016 - Results
History
2016-05-28 12:36:54
 Task: Graph painting Sender: Game of Nolife Submission time: 2016-05-28 12:36:54 Language: C++ Status: READY Result: ACCEPTED

Test results

 test verdict time (s) #1 ACCEPTED 0.06 / 1.00 details #2 ACCEPTED 0.05 / 1.00 details #3 ACCEPTED 0.15 / 1.00 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 6 7 4 6 2 3 3 5 7 8 4 8 5 7 5 6 4 7 6 8 1 4 2 6 4 5 3 8 2 8 ...```
view   save

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 B R B B B B R B R B R B B B R B R B R B R R B R B R R R R R B B R B R R R R B R R R R B B R R R B B B R B R R R R B R B B B R B R B B R R B R B B B R R ...```
view   save

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 B B R R B R B R B R B R B R B R B R B R B R B R R B R B R B R B R R B R B R B R B R B R R R R B B B B R B R B R R B R R R B R B R B B B R B R B B R R B ...```
view   save

Test 2

Verdict: ACCEPTED

input
```10 38 36 18 28 20 37 22 38 17 33 17 30 26 34 12 37 1 18 36 37 33 34 24 34 18 22 3 11 3 28 29 33 16 35 25 38 10 23 ...```
view   save

correct output
```R R B R B R R R R R B B R B R ... R R B B B R R B R B R B R B R ... B B R R R R B R B B B R R B R ... R R B R B B R B B R R R B B B B R B B B R R ... R R B B R R R B R R B R R R B ... B R R B R B B B R R R R B B R R B B B R R B R B B B B B ... R R B R R R R R B R B B R R R ... R R B R B B R R B R B B B R B ...```
view   save

user output
```R B R R R B R B R B B B R R R ... R B B B R B R B R R R B R B R ... R B R B R B R B R B R B R B R ... R B B B R B R R B R B B B B B R B R R B B R ... R B R B B B R R B B R B R R B ... R B R R B B B R R B R B R R B R B B B R B R B R B R B R ... R B R B R B R B R B R B R B R ... R B R B R B B B R B R B B B R ...```
view   save

Test 3

Verdict: ACCEPTED

input
```1 100000 200000 89300 98492 33853 56822 92967 99427 42461 62590 20195 38987 80870 85808 20624 64006 62088 88344 8872 92190 42562 66966 12882 52315 1520 96552 45353 90886 94940 99227 53663 62317 43160 66687 93275 93293 97160 97656 ...```
view   save

correct output
`R R R R B R R R B B B R B B B ...`
view   save

user output
`B B R B B R R B R B B R B B R ...`
view   save