fork download
  1. outb = {1: [2],
  2. 2: [3],
  3. 3: [2]}
  4.  
  5. def BFS(v1, v2):
  6. parsed = []
  7. toParse = [v1]
  8. current = v1
  9.  
  10. while len(toParse) > 0:
  11.  
  12. while current in parsed:
  13. current = toParse.pop(0)
  14.  
  15. if current not in outb:
  16. return False
  17.  
  18. if v2 in outb[current]:
  19. return True
  20.  
  21. toParse += outb[current]
  22. parsed.append(current)
  23.  
  24. return False
  25.  
  26. print(BFS(2, 1))
Runtime error #stdin #stdout #stderr 0.01s 27664KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 26, in <module>
  File "./prog.py", line 13, in BFS
IndexError: pop from empty list