Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def dfs(v):
- for i in g[v]:
- if not used[i]:
- used[i] = 1
- if not colors[v]: # red
- colors[i] = 1
- else:
- colors[i] = 0
- dfs(i)
- else:
- if colors[v] == colors[i]:
- print(-1)
- exit(0)
- y = 0
- n = int(input())
- g = dict()
- for i in range(1, n + 1):
- if i not in g:
- g[i] = set()
- m = [int(i) for i in input().split()]
- for j in m:
- if j == 0:
- break
- g[i].add(j)
- if j not in g:
- g[j] = set()
- g[j].add(i)
- used = [0] * (n + 1)
- colors = [0] * (n + 1)
- dfs(1)
- for i in range(1, n+1):
- print(colors[i], end="")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement