forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvivoparc.cpp
49 lines (45 loc) · 1.01 KB
/
vivoparc.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
48
49
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> adj;
vector<int> type;
void solve(int pos) {
int n = type.size();
if(pos == type.size()) {
for(int i = 0; i < n; ++i) {
cout << i+1 << ' ' << type[i] << '\n';
}
exit(0);
}
for(int color = 1; color <= 4; ++color) {
bool good = true;
for(const int &to : adj[pos]) {
if(to >= pos) break;
if(type[to] == color) {
good = false;
break;
}
}
if(good) {
type[pos] = color;
solve(pos+1);
}
}
}
int main() {
int n;
cin >> n;
adj.resize(n);
type.resize(n);
int u, v;
char dash;
while(cin >> u >> dash >> v) {
u--,v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i = 0; i < n; ++i) {
sort(adj[i].begin(), adj[i].end());
adj[i].erase(unique(adj[i].begin(), adj[i].end()), adj[i].end());
}
solve(0);
}