-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1080.cpp
More file actions
52 lines (45 loc) · 823 Bytes
/
1080.cpp
File metadata and controls
52 lines (45 loc) · 823 Bytes
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
50
51
52
#include <bits/stdc++.h>
#define int long long
using namespace std;
bool f;
vector<vector<int> > g;
vector<int> used;
vector<int> ans;
void dfs(int v, int p) {
used[v] = 1;
for(int i = 0; i < g[v].size(); i++) {
int to =g[v][i];
if(to==p) continue;
if(used[to] && ans[v]==ans[to]) {
f=false;
return;
}
if(!used[to]) {
ans[to] = 1-ans[v];
dfs(to,v);
}
}
}
main()
{
int n;
cin >> n;
used.resize(n);
ans.resize(n);
g.resize(n);
for(int i = 0; i < n; i++) {
int x;
while(cin>>x && x) {
x--;
g[i].push_back(x);
g[x].push_back(i);
}
}
f = true;
dfs(0,-1);
if(!f) {
cout << -1;
return 0;
}
for(int i = 0; i < n; i++) cout << ans[i];
}