CSES - E4590 2016 2 - Results
Submission details
Task:Graph painting
Sender:ivan
Submission time:2016-09-24 15:42:51 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.06 sdetails
#2ACCEPTED0.05 sdetails
#3ACCEPTED0.19 sdetails

Code

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>

using namespace std;

int coloring[100000];

int main(int argc, char *argv[])
{
    int t;
    cin >> t;

    for (int i = 0; i < t; ++i) {
        int n, m;
        cin >> n >> m;

        for (int j = 0; j < m; ++j) {
            int a, b;
            cin >> a >> b;
            a--;
            b--;

            if (coloring[a] == 0 && coloring[b] == 0) {
                coloring[a] = 1;
                coloring[b] = 2;
            } else if (coloring[a] == 1 && coloring[b] == 0) {
                coloring[b] = 2;
            } else if (coloring[a] == 2 && coloring[b] == 0) {
                coloring[b] = 1;
            } else if (coloring[a] == 0 && coloring[b] == 1) {
                coloring[a] = 2;
            } else if (coloring[a] == 0 && coloring[b] == 2) {
                coloring[a] = 1;
            }
        }

        for (int i = 0; i < n; ++i) {
            printf(coloring[i] == 1 ? "R " : "B ");
        }

        printf("\n");

        memset(coloring, 0, 100000);
    }

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