1097. Number of Restricted Paths

HardGraphsShortest PathDynamic ProgrammingHeap

Given a connected undirected weighted graph with n nodes and edges [u, v, w], let dist(x) be the shortest distance from x to node n-1. A restricted path from node 0 to node n-1 visits nodes whose dist values strictly decrease. Return the number of restricted paths modulo 1000000007. The input is JSON {n, edges}.

Input: JSON {n, edges} with edges [u, v, w].

Output: Integer — the number of restricted paths, modulo 1e9+7.

Examples

Example 1
Input: {"n":5,"edges":[[0,1,3],[0,2,3],[1,2,1],[0,3,2],[4,1,2],[2,4,1],[4,3,10]]}
Output: 3
Explanation: Three strictly-decreasing paths.
Example 2
Input: {"n":2,"edges":[[0,1,5]]}
Output: 1
Explanation: One direct path.
Example 3
Input: {"n":3,"edges":[[0,1,1],[1,2,1],[0,2,2]]}
Output: 2
Explanation: Two restricted paths.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →