Facebook
From minhhnh, 1 Month ago, written in Python.
Embed
Download Paste or View Raw
Hits: 116
  1. @cache
  2. def dfs(root, dest):
  3.     if root == dest:
  4.         return 1
  5.     path_count = 0
  6.     vis.add(root)
  7.     for node, _ in graph[root]:
  8.         if node not in vis and distance[node] > distance[root]:
  9.             path_count+= dfs(node, dest)
  10.     vis.remove(root)
  11.     return path_count
  12. return dfs(n-1, 0)%(10**9+7)