1928. Minimum Cost to Reach Destination in Time Hard
1/**
2 * [1928] Minimum Cost to Reach Destination in Time
3 *
4 * There is a country of n cities numbered from 0 to n - 1 where all the cities are connected by bi-directional roads. The roads are represented as a 2D integer array edges where edges[i] = [xi, yi, timei] denotes a road between cities xi and yi that takes timei minutes to travel. There may be multiple roads of differing travel times connecting the same two cities, but no road connects a city to itself.
5 * Each time you pass through a city, you must pay a passing fee. This is represented as a 0-indexed integer array passingFees of length n where passingFees[j] is the amount of dollars you must pay when you pass through city j.
6 * In the beginning, you are at city 0 and want to reach city n - 1 in maxTime minutes or less. The cost of your journey is the summation of passing fees for each city that you passed through at some moment of your journey (including the source and destination cities).
7 * Given maxTime, edges, and passingFees, return the minimum cost to complete your journey, or -1 if you cannot complete it within maxTime minutes.
8 *
9 * Example 1:
10 * <img alt="" src="https://assets.leetcode.com/uploads/2021/06/04/leetgraph1-1.png" style="width: 371px; height: 171px;" />
11 *
12 * Input: maxTime = 30, edges = [[0,1,10],[1,2,10],[2,5,10],[0,3,1],[3,4,10],[4,5,15]], passingFees = [5,1,2,20,20,3]
13 * Output: 11
14 * Explanation: The path to take is 0 -> 1 -> 2 -> 5, which takes 30 minutes and has $11 worth of passing fees.
15 *
16 * Example 2:
17 * <img alt="" src="https://assets.leetcode.com/uploads/2021/06/04/copy-of-leetgraph1-1.png" style="width: 371px; height: 171px;" />
18 *
19 * Input: maxTime = 29, edges = [[0,1,10],[1,2,10],[2,5,10],[0,3,1],[3,4,10],[4,5,15]], passingFees = [5,1,2,20,20,3]
20 * Output: 48
21 * Explanation: The path to take is 0 -> 3 -> 4 -> 5, which takes 26 minutes and has $48 worth of passing fees.
22 * You cannot take path 0 -> 1 -> 2 -> 5 since it would take too long.
23 *
24 * Example 3:
25 *
26 * Input: maxTime = 25, edges = [[0,1,10],[1,2,10],[2,5,10],[0,3,1],[3,4,10],[4,5,15]], passingFees = [5,1,2,20,20,3]
27 * Output: -1
28 * Explanation: There is no way to reach city 5 from city 0 within 25 minutes.
29 *
30 *
31 * Constraints:
32 *
33 * 1 <= maxTime <= 1000
34 * n == passingFees.length
35 * 2 <= n <= 1000
36 * n - 1 <= edges.length <= 1000
37 * 0 <= xi, yi <= n - 1
38 * 1 <= timei <= 1000
39 * 1 <= passingFees[j] <= 1000
40 * The graph may contain multiple edges between two nodes.
41 * The graph does not contain self loops.
42 *
43 */
44pub struct Solution {}
45
46// problem: https://leetcode.com/problems/minimum-cost-to-reach-destination-in-time/
47// discuss: https://leetcode.com/problems/minimum-cost-to-reach-destination-in-time/discuss/?currentPage=1&orderBy=most_votes&query=
48
49// submission codes start here
50
51impl Solution {
52 pub fn min_cost(max_time: i32, edges: Vec<Vec<i32>>, passing_fees: Vec<i32>) -> i32 {
53 0
54 }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61 use super::*;
62
63 #[test]
64 fn test_1928() {
65 }
66}
67
Back
© 2025 bowen.ge All Rights Reserved.