Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import collections
- def bfs(v):
- d[v],e=0,collections.deque([v])
- while len(exp) != 0:
- a = exp.popleft()
- for i in g[a]:
- if i not in d:
- d[i]=d[a]+1;exp.append(i)
- g,d,e,n = {},{},collections.deque(),int(input())
- for i in range(n):
- x = input().split()
- for i in x:
- if i not in g:
- g[i]=set()
- g[x[0]].add(x[1]);g[x[0]].add(x[2]);g[x[1]].add(x[0]);g[x[1]].add(x[2]);g[x[2]].add(x[1]);g[x[2]].add(x[0])
- if "Isenbaev" in g:
- bfs("Isenbaev")
- for i in g:
- if i not in d:
- d[i]='undefined'
- for i in sorted(g):
- try:
- print(i,d[i])
- except:
- print(i,"undefined")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement