-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1080.cpp
45 lines (38 loc) · 915 Bytes
/
1080.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
#include <iostream>
using namespace std;
#define MAX_N 99
bool edges[MAX_N][MAX_N];
bool colors[MAX_N], colored[MAX_N];
bool paint(int n, int i, bool predColor = true) {
if (colored[i]) return colors[i] != predColor;
colored[i] = true;
bool color = colors[i] = !predColor;
for (int node = 1; node <= n; ++node) {
if (!edges[i][node]) continue;
if (!paint(n, node, color)) return false;
}
return true;
}
int main() {
int n;
cin >> n;
int node;
for (int i = 1; i <= n; ++i) {
cin >> node;
if (node == 0) continue;
while (node > 0) {
edges[node][i] = true;
edges[i][node] = true;
cin >> node;
}
}
if (!paint(n,1)) {
cout << "-1";
return 0;
}
cout << noboolalpha;
for (int i = 1; i <= n; ++i) {
cout << colors[i];
}
return 0;
}