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 12:04:10
Task:Graph painting
Sender:Team Purkka
Submission time:2016-05-28 12:04:10
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main () {
  srand(time(0));
  int t;
  cin>>t;
  for (int ca = 0; ca < t; ca++) {
     int n, m;
     cin>>n>>m;
     vector<pair<int, int>> v;
     for (int i = 0; i < m; i++) {
	int a, b;
	cin>>a>>b;
	v.push_back({a, b});
     }
     while (true) {
	int c[n + 1];
	for (int i = 1; i <= n; i++) c[i] = rand() % 2;
	int s = 0;
	for (int i = 0; i < m; i++) {
	    if (c[v[i].first] != c[v[i].second]) s++;
	}
	if (s >= m / 2) {
	  for (int i = 1; i <= n; i++) {
	    if (c[i]) cout<<"B ";
	    else cout<<"R ";
	  }
	  cout<<endl;
	  break;
	}
     }
  }
}