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 15:00:25
2016-05-28 13:39:35
2016-05-28 13:09:34
Task:Graph painting
Sender:Verto
Submission time:2016-05-28 13:39:35
Status:READY
Result:TIME LIMIT EXCEEDED

Show test data

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