Code Submission Evaluation System Login

CSES - HIIT Open 2016

HIIT Open 2016

Contest start:2016-05-28 11:00:00
Contest end:2016-05-28 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2016-05-28 13:04:17
Task:Graph painting
Sender:Ace of Spades
Submission time:2016-05-28 13:04:17
Status:READY
Result:ACCEPTED

Show test data

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;
}