fork download
  1. from collections import deque
  2.  
  3. graph={'A':['B','C'],'B':['D','E'],'C':['F','G']}
  4. def bfs(graph,start):
  5. queue=deque(start)
  6. visited=[]
  7. last=''
  8. while(queue):
  9. u=queue.popleft()
  10. last=u
  11. for v in graph[u]:
  12. if v not in visited:
  13. visited.append(v)
  14. start,last=last,start
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
Runtime error #stdin #stdout 0.03s 6352KB
stdin
stdout
Standard output is empty