Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- sys.setrecursionlimit(100000)
- def DFS(s):
- used[s] = True
- for i in graph_list[s]:
- if color[s] == color[i] and used[i]:
- return False
- elif not used[i]:
- if color[s] == 1:
- color[i] = 0
- else:
- color[i] = 1
- res = DFS(i)
- if not res:
- return False
- return True
- K, M = map(int, input().split())
- graph_list = [list() for _ in range(K)]
- for i in range(M):
- x, y = map(int, input().split())
- graph_list[x - 1].append(y - 1)
- graph_list[y - 1].append(x - 1)
- used = [False] * K
- color = [0] * K
- answer = DFS(0)
- if answer:
- print('YES')
- else:
- print('NO')
Advertisement
Add Comment
Please, Sign In to add comment