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

Compiler report

input/code.cpp: In function 'void paint(int, int)':
input/code.cpp:15:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < AdjList[u].size(); ++i){
                                     ^

Code

#include <bits/stdc++.h>
#define UNVISITED -1
#define BIGINT 1 << 25
#define _ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);
using namespace std;

typedef long long int64;
typedef pair<int, int> ii;

vector<int> color;
vector< vector<int> > AdjList;

void paint(int u, int c){
	color[u] = c;
	for(int i = 0; i < AdjList[u].size(); ++i){
		int v = AdjList[u][i];
		if(color[v] == UNVISITED)
			paint(v, 1 - c);
	}
}

int main(){ _
	int tc;	cin >> tc;
	while(tc--){
		int n, m;	cin >> n >> m;
		color.assign(n+1, UNVISITED);
		AdjList.assign(n + 1, vector<int> (0));
	
	
		int u, v;
		for(int i = 0; i < m; ++i){
			cin >> u >> v;
			AdjList[u].push_back(v);
		}
	
		for(int i = 1; i <= n; ++i)
			if(color[i] == UNVISITED)
				paint(i, 0);
		
		for(int i = 1; i <= n; ++i){
			if(color[i])	cout << 'R';
			else	cout << 'B';

			if(i + 1 <= n)	cout << " ";
			else	cout << endl;
		}	
		
	}
    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 B R B
B R B R B B B B R B
B R B R R B
B R R R B 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
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 ...