Number of Ways to Arrive at Destination
There are n intersections labeled 0..n-1 connected by bidirectional roads, where roads[i] = [u, v, time] takes the given time to travel. Starting at intersection 0, return the number of different ways to reach intersection n-1 in the shortest possible time, modulo 10^9 + 7.
Open official problem prompt ↗Count how many distinct fastest routes exist from intersection 0 to intersection n-1.
A GPS not only reports the quickest driving time but tallies how many different quickest routes tie for first place.
- Input
- n = 7, roads = [[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
- Why
- The shortest time from 0 to 6 is 7, and exactly 4 distinct routes achieve it (including the direct road 0->6).
1 <= n <= 200n - 1 <= roads.length <= n*(n-1)/2roads[i].length == 30 <= u, v <= n - 1, u != v1 <= time <= 10^9There is at most one road between any two intersectionsYou can reach any intersection from any other intersection