fork download
  1. outb = {1: [2],
  2. 2: [4, 5],
  3. 3: [5, 11, 12],
  4. 4: [6, 7],
  5. 5: [7],
  6. 6: [9, 10],
  7. 7: [8],
  8. 11: [3],
  9. 12: [15, 14, 13],
  10. 13: [17],
  11. 14: [17],
  12. 15: [12, 5, 8, 16],
  13. 17: [18]}
  14.  
  15. def BFS(v1, v2):
  16. parsed = []
  17. toParse = [v1]
  18. current = v1
  19.  
  20. while len(toParse) > 0:
  21.  
  22. while current in parsed:
  23. current = toParse.pop(0)
  24.  
  25. if current not in outb:
  26. return False
  27.  
  28. if v2 in outb[current]:
  29. return True
  30.  
  31. toParse += outb[current]
  32. parsed.append(current)
  33.  
  34. return False
  35.  
  36. print(BFS(1, 18))
Success #stdin #stdout 0.01s 28384KB
stdin
Standard input is empty
stdout
False