Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def dfs(h):
- global answ
- used[h] = 1
- for e in g[h]:
- if used[e] == 0:
- col[e] = col[h] ^ 1
- dfs(e)
- else:
- if col[e] == col[h]:
- answ = False
- n, m = map(int, input().split())
- g = [[] for i in range(n)]
- for i in range(m):
- x, y = map(int, input().split())
- x -= 1
- y -= 1
- g[x].append(y)
- g[y].append(x)
- used = [0] * n
- col = [-1] * n
- col[0] = 0
- answ = True #граф двудольный
- dfs(0)
- print(answ)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement