fork download
  1. graph={
  2. "A":["B","D","E"],
  3. "B":["A","C"],
  4. "C":["B","E"],
  5. "D":["A","E"],
  6. "E":["A","D","F","C"],
  7. "F":["E"]
  8. }
  9.  
  10. def bfs(graph,start):
  11. queue=[]
  12. queue.append(start)
  13. result=[]
  14. visited=set()
  15. visited.add(start)
  16. while(len(queue)>0):
  17. currentVertex=queue.pop(0)
  18. result.append(currentVertex)
  19. for neighbor in graph[currentVertex]:
  20. if neighbor not in visited:
  21. queue.append(neighbor)
  22. visited.add(neighbor)
  23. return result
Success #stdin #stdout 0.11s 14116KB
stdin
Standard input is empty
stdout
Standard output is empty