Class Solution
- java.lang.Object
-
- g1901_2000.s1976_number_of_ways_to_arrive_at_destination.Solution
-
public class Solution extends Object
1976 - Number of Ways to Arrive at Destination.Medium
You are in a city that consists of
nintersections numbered from0ton - 1with bi-directional roads between some intersections. The inputs are generated such that you can reach any intersection from any other intersection and that there is at most one road between any two intersections.You are given an integer
nand a 2D integer arrayroadswhereroads[i] = [ui, vi, timei]means that there is a road between intersectionsuiandvithat takestimeiminutes to travel. You want to know in how many ways you can travel from intersection0to intersectionn - 1in the shortest amount of time.Return the number of ways you can arrive at your destination in the shortest amount of time. Since the answer may be large, return it modulo
109 + 7.Example 1:

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
Explanation: The shortest amount of time it takes to go from intersection 0 to intersection 6 is 7 minutes. The four ways to get there in 7 minutes are:
-
0 \u279d 6
-
0 \u279d 4 \u279d 6
-
0 \u279d 1 \u279d 2 \u279d 5 \u279d 6
-
0 \u279d 1 \u279d 3 \u279d 5 \u279d 6
Example 2:
Input: n = 2, roads = [[1,0,10]]
Output: 1
Explanation: There is only one way to go from intersection 0 to intersection 1, and it takes 10 minutes.
Constraints:
1 <= n <= 200n - 1 <= roads.length <= n * (n - 1) / 2roads[i].length == 30 <= ui, vi <= n - 11 <= timei <= 109ui != vi- There is at most one road connecting any two intersections.
- You can reach any intersection from any other intersection.
-
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcountPaths(int n, int[][] roads)
-