forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsabor.cpp
47 lines (38 loc) · 891 Bytes
/
sabor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string color(n, 'A');
vector<vector<int>> adj(n);
for(int i = 0; i < 5; i++) {
int t;
cin >> t;
for(int j = 0; j < t; j++) {
int n1, n2;
cin >> n1 >> n2;
n1--; n2--;
adj[n1].push_back(n2);
adj[n2].push_back(n1);
}
}
queue<int> q;
for(int i = 0; i < n; i++) {
q.push(i);
}
while(!q.empty()) {
int curr = q.front();
q.pop();
int match = 0;
for(auto next : adj[curr]) {
if(color[next] == color[curr]) match++;
}
if(match > 2) {
color[curr] = color[curr] ^ 'A' ^ 'B';
for(auto next : adj[curr]) {
q.push(next);
}
}
}
cout << color << endl;
}