davegimo

Untitled

Jun 9th, 2022
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. def path(T,s,current):
  2. return find_path(T,s,current,0)
  3.  
  4. def find_path(T,s,current,count):
  5.  
  6. for element in T:
  7.  
  8. if element[1] == current:
  9.  
  10. if element[0] == s:
  11. return count + 1
  12.  
  13. else:
  14. return find_path(T,s,element[0],count + 1)
  15.  
  16. return -1
  17.  
  18. def check_connection_k(T,s,d,k):
  19. numero_salti = path(T,s,d)
  20.  
  21. if numero_salti == -1:
  22. return False
  23.  
  24. if numero_salti <= k:
  25. return True
  26.  
  27. return False
  28.  
  29.  
  30. T = [[0,1],[1,3],[3,6],[6,8],[8,10]]
  31.  
  32. print(check_connection_k(T,0,10,5))
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment