Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n, m = list(map(int, input().split()))
- graph = [[] for i in range(n)]
- for i in range(m):
- x, y = list(map(int, input().split()))
- graph[x - 1].append(y - 1)
- graph[y - 1].append(x - 1)
- color = [-1 for i in range(n)]
- def dfs(x):
- global graph, res_1
- for i in range(len(graph[x])):
- if color[graph[x][i]] == -1:
- color[graph[x][i]] = (color[x] + 1) % 2
- dfs(graph[x][i])
- else:
- if color[graph[x][i]] == color[x]:
- res_1 = False
- return
- res = True
- for i in range(n):
- if color[i] == -1:
- color[i] = 0
- res_1 = True
- dfs(i)
- res = res and res_1
- if res:
- print('YES')
- for i in range(len(color)):
- if color[i] == 0:
- print(i + 1, end=' ')
- else:
- print('NO')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement