Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def bfc(start_node, graph):
- visited = []
- distance = {str(i): '' for i in range(1, len(graph) + 1)}
- queue = [start_node]
- while len(queue) != 0:
- i = queue[0]
- queue.remove(i)
- for s, w in graph[i]:
- if s in visited:
- continue
- visited.append(s)
- distance[str(s)] = w
- queue.append(s)
- return distance
Advertisement
Add Comment
Please, Sign In to add comment