Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def dfs(h):
- used[h] = True
- for e in g[h]:
- if not used[e]:
- dfs(e)
- 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 = [False] * n
- dfs(0)
Advertisement
Add Comment
Please, Sign In to add comment