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:26:11
Task:Graph painting
Sender:Anonyymit Algoritmistit
Submission time:2016-05-28 15:26:11
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  ll t;
  cin >> t;
  
  for(int j = 0; j < t; j++) {
    
    vector<vector<ll>> verkko;
    vector<bool> varit;
    
    ll n,m;
    cin >> n >> m;
    
    verkko.resize(n+1);
    varit.resize(n+1);
    
    for(int i = 1; i <= n; i++) {
      verkko[i] = vector<ll>();
    }
    
    
    for(int i = 0; i < m; i++) {
      ll x,y;
      cin >> x >> y;
      verkko[x].push_back(y);
      verkko[y].push_back(x);
    }
    
    for(int i = 1; i <= n; i++) {
      ll c = 0;
      for(auto a : verkko[i]) {
	if (varit[a] == varit[i]) c++;
	else c--;
      }
      if (c > 0) varit[i] = !varit[i];
    }
    
    for(int i = 1; i <= n; i++) {
      if (varit[i]) cout << "R ";
      else cout << "B ";
    }
    cout << endl;
    
  }
  
  
}