1976. Number of Ways to Arrive at Destination Medium
1/**
2 * [1976] Number of Ways to Arrive at Destination
3 *
4 * You are in a city that consists of n intersections numbered from 0 to n - 1 with 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.
5 * You are given an integer n and a 2D integer array roads where roads[i] = [ui, vi, timei] means that there is a road between intersections ui and vi that takes timei minutes to travel. You want to know in how many ways you can travel from intersection 0 to intersection n - 1 in the shortest amount of time.
6 * 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 10^9 + 7.
7 *
8 * Example 1:
9 * <img alt="" src="https://assets.leetcode.com/uploads/2021/07/17/graph2.png" style="width: 235px; height: 381px;" />
10 * 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]]
11 * Output: 4
12 * Explanation: The shortest amount of time it takes to go from intersection 0 to intersection 6 is 7 minutes.
13 * The four ways to get there in 7 minutes are:
14 * - 0 ➝ 6
15 * - 0 ➝ 4 ➝ 6
16 * - 0 ➝ 1 ➝ 2 ➝ 5 ➝ 6
17 * - 0 ➝ 1 ➝ 3 ➝ 5 ➝ 6
18 *
19 * Example 2:
20 *
21 * Input: n = 2, roads = [[1,0,10]]
22 * Output: 1
23 * Explanation: There is only one way to go from intersection 0 to intersection 1, and it takes 10 minutes.
24 *
25 *
26 * Constraints:
27 *
28 * 1 <= n <= 200
29 * n - 1 <= roads.length <= n * (n - 1) / 2
30 * roads[i].length == 3
31 * 0 <= ui, vi <= n - 1
32 * 1 <= timei <= 10^9
33 * ui != vi
34 * There is at most one road connecting any two intersections.
35 * You can reach any intersection from any other intersection.
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/number-of-ways-to-arrive-at-destination/
41// discuss: https://leetcode.com/problems/number-of-ways-to-arrive-at-destination/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn count_paths(n: i32, roads: Vec<Vec<i32>>) -> i32 {
47 0
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_1976() {
59 }
60}
61
Back
© 2025 bowen.ge All Rights Reserved.