CSES - HIIT Open 2016 - Results
Submission details
Task:Graph painting
Sender:Verto
Submission time:2016-05-28 13:39:35 +0300
Language:Java
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.23 sdetails
#2ACCEPTED0.18 sdetails
#3--details

Code

import java.util.Vector;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;

public class G {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		for(int i = 0; i < t; i++) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			Vector<Node> nodes = new Vector<Node>(n);
			for(int j=0; j<n; j++)
				nodes.add(new Node(j));

			for(int j=0; j<m; j++) {
				int u = sc.nextInt() - 1;
				int v = sc.nextInt() - 1;
				nodes.get(u).connect(nodes.get(v));
			}
			for(Node node : nodes) {
				int n_red = 0;
				int n_blue = 0;
				for(Node neigh : node.neighbors) {
					if(neigh.color == 'R')
						n_red += 1;
					else if(neigh.color == 'B')
						n_blue += 1;
				}
				if(n_red > n_blue)
					node.color = 'B';
				else
					node.color = 'R';
				System.out.print(node.color + " ");
			}
			System.out.println();
		}
	}

}

class Node {
	public List<Node> neighbors;
	public int name;
	public char color;
	public Node(int name) {
		this.name = name;
		this.neighbors = new ArrayList<Node>();
		this.color = '-';
	}
	public void connect(Node other) {
		this.neighbors.add(other);
		other.neighbors.add(this);
	}
}

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

Test 3

Verdict:

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
(empty)