achulkov2

Untitled

Dec 8th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. import sys
  2. sys.setrecursionlimit(100000)
  3.  
  4.  
  5. def DFS(s):
  6. used[s] = True
  7. for i in graph_list[s]:
  8. if color[s] == color[i] and used[i]:
  9. return False
  10. elif not used[i]:
  11. if color[s] == 1:
  12. color[i] = 0
  13. else:
  14. color[i] = 1
  15. res = DFS(i)
  16. if not res:
  17. return False
  18. return True
  19.  
  20.  
  21. K, M = map(int, input().split())
  22. graph_list = [list() for _ in range(K)]
  23. for i in range(M):
  24. x, y = map(int, input().split())
  25. graph_list[x - 1].append(y - 1)
  26. graph_list[y - 1].append(x - 1)
  27. used = [False] * K
  28. color = [0] * K
  29. answer = DFS(0)
  30. if answer:
  31. print('YES')
  32. else:
  33. print('NO')
Advertisement
Add Comment
Please, Sign In to add comment