Fast Easy JS Solution | dijkstras + dfs + dp | 70% faster
\nvar countRestrictedPaths = function(n, edges) {\n    const g = Array.from({ length: n + 1}, () => []);\n    for(let [a, b, c] of edges) {\n        g[a].push([
```\nvar countRestrictedPaths = function(n, edges) {\n    const g = Array.from({ length: n + 1}, () => []);\n    for(let [a, b, c] of edges) {\n        g[a].push([b, c]);\n        g[b].push([a, c]);\n    }\n    // do dijkstras to find shortest path from n to all nodes\n    const dis = new Array(n + 1).fill(Infinity);\n    dis[n] = 0;\n    const dijkstra = () => {\n        const heap = new MinPriorityQueue({ priority: (x) => x[1] });\n        heap.enqueue([n, 0]);\n        while(heap.size()) {\n            const [node, cost] = heap.dequeue().element;\n            for(let [nextNode, w] of g[node]) {\n                const totalCost = cost + w;\n                if(dis[nextNode] > totalCost) {\n                    dis[nextNode] = totalCost;\n                    heap.enqueue([nextNode, totalCost]);\n                }\n            }\n        }\n    }\n    dijkstra();\n    \n    // do dfs from 1 having path always lesser dist\n    let rPaths = 0;\n    const MOD = 1000000007;\n    const dp = new Array(n + 1).fill(-1);\n    const dfs = (curr = 1, rCost = dis[1]) => {\n        if(curr == n) return 1;\n        if(dp[curr] != -1) return dp[curr];\n        \n        let op = 0;\n        for(let [n, w] of g[curr]) {\n            if(dis[n] < rCost) {\n                op = (op + dfs(n, dis[n])) % MOD;\n            }\n        }\n        \n        return dp[curr] = op;\n    }\n    return dfs();\n};\n```
['JavaScript']