Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def dfs(h): #h->v
- used[h] = True
- for v in g[h]:
- if not used[v]:
- dfs(v)
- 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
Advertisement