Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import defaultdict
- n, m = map(int, input().split())
- g = defaultdict(list)
- for i in range(m):
- a, b = map(int, input().split())
- g[a].append(b)
- g[b].append(a)
- visited = [0] * 101
- def dfs(node, color):
- if not visited[node]:
- visited[node] = color
- res = True
- for neigh in g[node]:
- res = res and dfs(neigh, -1 * color)
- return res
- elif visited[node] == color:
- return True
- else:
- return False
- res = True
- for v in range(1, n+1):
- if not visited[v]:
- res = res and dfs(v, 1)
- if res:
- print('YES')
- print(' '.join([str(i) for i, v in enumerate(visited) if v == 1]))
- else:
- print('NO')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement