CSES - HIIT Open 2016 - Results
Submission details
Task:Graph painting
Sender:Ace of Spades
Submission time:2016-05-28 13:04:17 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#2ACCEPTED0.05 sdetails
#3ACCEPTED0.13 sdetails

Code

#include<bits/stdc++.h>

using namespace std;
const int MN = 1e5+100;
int color[MN];
vector<int> v[MN];

int main(void) {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    int tt;
    cin>>tt;
    for(int xx = 0; xx < tt; ++xx) {
        int n;
        int m;
        cin>>n>>m;
        for(int i = 0; i < m; ++i) {
            int a,b;
            cin>>a>>b;
            v[a].push_back(b);
            v[b].push_back(a);
        }
        color[1] = 1;
        for(int i = 2; i <= n; ++i) {
            int q = 0;
            int w = 0;
            for(auto x: v[i]) {
                if(color[x] == 1) ++q;
                if(color[x] == 2) ++w;
            }
            if(q > w) color[i] = 2;
            else {
                color[i] = 1;
            }
        }
        for(int i = 1; i <= n; ++i) {
            if(color[i] == 1) cout<<"B ";
            else cout<<"R ";
            color[i] = 0;
            v[i].clear();
        }
        cout<<'\n';
    }


    return 0;
}

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
B B B B R B B 
B R B R B R B R 
B R B R B B B B R B 
B R B R B R 
B R R B B B R R B 
...

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
B B B B B B B B B B R B B B B ...

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 B B B B B B B B B B B B B ...