1073. Number of Ways to Arrive at Destination

MediumGraphsShortest PathDynamic ProgrammingGraph

Given a connected undirected weighted graph with n nodes and edges [u, v, w], return the number of distinct shortest paths from node 0 to node n-1, modulo 1000000007. The input is JSON {n, edges}.

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

Output: Integer — the count of shortest paths, modulo 1e9+7.

Examples

Example 1
Input: {"n":7,"edges":[[0,6,7],[0,1,2],[1,2,3],[1,3,3],[6,3,3],[3,5,1],[6,5,1],[2,5,1],[0,4,5],[4,6,2]]}
Output: 4
Explanation: Four shortest paths of equal length.
Example 2
Input: {"n":2,"edges":[[0,1,5]]}
Output: 1
Explanation: One path.
Example 3
Input: {"n":1,"edges":[]}
Output: 1
Explanation: Source equals destination.

Constraints

Asked by

GoogleMetaAmazonBloombergMicrosoft
Solve this problem in the editor →