Practice/Google/Leetcode 1786. Number of Restricted Paths From First to Last Node
CodingMust
You are given an undirected weighted graph with n nodes labeled from 1 to n, and a list of edges where each edge is represented as [u, v, weight], indicating a bidirectional edge between nodes u and v with the given weight.
A restricted path is a path from node 1 to node n such that:
1 and ends at node nn is strictly greater than the shortest distance from the next node to node nIn other words, as you traverse the path, you must always move to a node that is strictly closer to the destination (node n) in terms of shortest path distance.
Return the number of restricted paths from node 1 to node n. Since the answer may be very large, return it modulo 10^9 + 7.
n using an appropriate shortest path algorithm1 to node n where the distance-to-destination strictly decreases at each step10^9 + 71 <= n <= 2 * 10^4n - 1 <= edges.length <= 4 * 10^4edges[i].length == 31 <= u_i, v_i <= nu_i != v_i1 <= weight_i <= 10^51 to node nExample 1:
` Input: n = 3, edges = [[1,2,3],[2,3,1],[1,3,4]] Output: 3 Explanation:
Example 2:
` Input: n = 4, edges = [[1,2,1],[2,3,1],[3,4,1]] Output: 1 Explanation:
Example 3:
Input: n = 2, edges = [[1,2,100]] Output: 1 Explanation: Only one path exists: 1 -> 2