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 15:00:25
Status:READY
Result:ACCEPTED

Show test data

Code

#include <iostream>
#include <string>
#include <vector>

using namespace std;

class Node {
public:
	vector<Node*> neighbors;
	int name;
	char color;
	// Constructor TODO
	Node(int name_) {
		name = name_;
		color = '-';
	}
	void connect(Node* other) {
		neighbors.push_back(other);
		other->neighbors.push_back(this);
	}
};

int main() {
	int t;
	cin >> t;

	for (int i = 0; i < t; i++) {
		int n,m;
		cin >> n >> m;
		vector<Node*> nodes;
		for(int j = 0; j < n; j++)
			nodes.push_back(new Node(j));
		for(int j=0; j<m; j++) {
			int u,v;
			cin >> u >> v;
			nodes[u-1]->connect(nodes[v-1]);
		}
		for(auto node : nodes) {
			int n_red = 0;
			int n_blue = 0;
			for(auto neigh : node->neighbors) {
				if(neigh->color == 'R')
					n_red += 1;
				else if(neigh->color == 'B')
					n_blue++;
			}
			if(n_red > n_blue)
				node->color = 'B';
			else
				node->color = 'R';
			cout << node->color << " ";
		}
		cout << endl;
	}
}