PlotnikovPhilipp

Untitled

Nov 18th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. def bfc(start_node, graph):
  2.     visited = []
  3.     distance = {str(i): '' for i in range(1, len(graph) + 1)}
  4.     queue = [start_node]
  5.     while len(queue) != 0:
  6.         i = queue[0]
  7.         queue.remove(i)
  8.         for s, w in graph[i]:
  9.             if s in visited:
  10.                 continue
  11.             visited.append(s)
  12.             distance[str(s)] = w
  13.             queue.append(s)
  14.     return distance
Advertisement
Add Comment
Please, Sign In to add comment