title: Find all paths between two nodes using DFS in weighted directed graph
body: <p>I had a <strong>directed weighted</strong> graph <strong>G</strong>, where weight is duration of transition.</p>
  
  <p>I wrote all paths search algorithm between two vertices using DFS with modification: the search continues until total weight of path (the sum of the weights of its parts) will be less some value.</p>
  
  <p>My code works in small graph, but in big graph (|V|=1800, |E|=50870) it freezes.</p>
  
  <pre><code>def find_paths(self, start, end, weight_limit=10):
          res = []
  
          def dfs(start, end, path=[], weight=0):
              path = path + [start]
              if len(path) &gt; 1:
                  weight += self.weights[(path[-2], start)]
              if weight &gt; weight_limit:
                  return []
              if start == end:
                  res.append((path, weight))
                  return [path]
              if start not in self.adjacent:
                  return []
              paths = []
              for node in self.adjacent[start]:
                  if node not in path:
                      paths.extend(dfs(node, end, path, weight))
              return paths
  
          dfs(start, end)
          return res
  </code></pre>