[Python] Clean + Short | Dijkstra's Algorithm + DFS + Memoization | 40 Line Solution
```\nfrom queue import PriorityQueue\n\nclass Solution:\n    def countRestrictedPaths(self, n: int, edges: List[List[int]]) -> int:\n        g = defaultdict(dic
```\nfrom queue import PriorityQueue\n\nclass Solution:\n    def countRestrictedPaths(self, n: int, edges: List[List[int]]) -> int:\n        g = defaultdict(dict)\n        \n        for u, v, w in edges: # create adjacency list\n            g[u][v] = w\n            g[v][u] = w\n        \n        def dijkstras(start): # calculate shortests paths\n            d = {v: float(\'inf\') for v in range(1, n+1)}\n            d[start] = 0\n            q = PriorityQueue()\n            q.put((0, start))\n            \n            while not q.empty():\n                u = q.get()[1]\n                \n                for v in g[u]:\n                    if d[u] + g[u][v] < d[v]:\n                        d[v] = d[u] + g[u][v]\n                        q.put((d[v], v))\n            \n            return d\n            \n        d = dijkstras(n)\n        seen = set()\n        \n        @cache\n        def dfs(node):\n            if node == n:\n                return 1\n            \n            seen.add(node)\n            count = 0\n            for neighbor in g[node].keys():\n                if d[neighbor] < d[node] and neighbor not in seen:\n                    count += dfs(neighbor)\n            seen.discard(node)\n            return count\n       \n        return dfs(1) % (10**9 + 7)
['Depth-First Search', 'Python']