Eddy_S

Untitled

May 12th, 2021
589
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def all_paths(self, s: Vertex, t: Vertex, k: int) -> list:
  2.     visited = [False] * len(self.vertices)
  3.     paths = []
  4.     path = []
  5.     path.append(s)
  6.     self.dfs(s, t, visited, path, paths)
  7.     print(paths)
  8.  
  9. def dfs(self, s: Vertex, t: Vertex, visited: list, path: list, paths: list):
  10.     visited[self.vertices.index(s)] = True
  11.     if s == t:
  12.         # print(path)
  13.         paths.append(path)
  14.         # print(paths)
  15.         return
  16.    
  17.     for adjacent in s.edges:
  18.         if not visited[self.vertices.index(adjacent)]:
  19.             path.append(adjacent)
  20.             self.dfs(adjacent, t, visited, path, paths)
  21.             path.remove(adjacent)
  22.     visited[self.vertices.index(s)] = False
RAW Paste Data