3112. Minimum Time to Visit Disappearing Nodes Medium
1/**
2 * [3112] Minimum Time to Visit Disappearing Nodes
3 *
4 * There is an undirected graph of n nodes. You are given a 2D array edges, where edges[i] = [ui, vi, lengthi] describes an edge between node ui and node vi with a traversal time of lengthi units.
5 * Additionally, you are given an array disappear, where disappear[i] denotes the time when the node i disappears from the graph and you won't be able to visit it.
6 * Note that the graph might be disconnected and might contain multiple edges.
7 * Return the array answer, with answer[i] denoting the minimum units of time required to reach node i from node 0. If node i is unreachable from node 0 then answer[i] is -1.
8 *
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io">n = 3, edges = [[0,1,2],[1,2,1],[0,2,4]], disappear = [1,1,5]</span>
12 * Output: <span class="example-io">[0,-1,4]</span>
13 * Explanation:
14 * <img alt="" src="https://assets.leetcode.com/uploads/2024/08/11/output-onlinepngtools.png" style="width: 350px; height: 210px;" />
15 * We are starting our journey from node 0, and our goal is to find the minimum time required to reach each node before it disappears.
16 *
17 * For node 0, we don't need any time as it is our starting point.
18 * For node 1, we need at least 2 units of time to traverse edges[0]. Unfortunately, it disappears at that moment, so we won't be able to visit it.
19 * For node 2, we need at least 4 units of time to traverse edges[2].
20 * </div>
21 * <strong class="example">Example 2:
22 * <div class="example-block">
23 * Input: <span class="example-io">n = 3, edges = [[0,1,2],[1,2,1],[0,2,4]], disappear = [1,3,5]</span>
24 * Output: <span class="example-io">[0,2,3]</span>
25 * Explanation:
26 * <img alt="" src="https://assets.leetcode.com/uploads/2024/08/11/output-onlinepngtools-1.png" style="width: 350px; height: 210px;" />
27 * We are starting our journey from node 0, and our goal is to find the minimum time required to reach each node before it disappears.
28 *
29 * For node 0, we don't need any time as it is the starting point.
30 * For node 1, we need at least 2 units of time to traverse edges[0].
31 * For node 2, we need at least 3 units of time to traverse edges[0] and edges[1].
32 * </div>
33 * <strong class="example">Example 3:
34 * <div class="example-block">
35 * Input: <span class="example-io">n = 2, edges = [[0,1,1]], disappear = [1,1]</span>
36 * Output: <span class="example-io">[0,-1]</span>
37 * Explanation:
38 * Exactly when we reach node 1, it disappears.
39 * </div>
40 *
41 * Constraints:
42 *
43 * 1 <= n <= 5 * 10^4
44 * 0 <= edges.length <= 10^5
45 * edges[i] == [ui, vi, lengthi]
46 * 0 <= ui, vi <= n - 1
47 * 1 <= lengthi <= 10^5
48 * disappear.length == n
49 * 1 <= disappear[i] <= 10^5
50 *
51 */
52pub struct Solution {}
53
54// problem: https://leetcode.com/problems/minimum-time-to-visit-disappearing-nodes/
55// discuss: https://leetcode.com/problems/minimum-time-to-visit-disappearing-nodes/discuss/?currentPage=1&orderBy=most_votes&query=
56
57// submission codes start here
58
59impl Solution {
60 pub fn minimum_time(n: i32, edges: Vec<Vec<i32>>, disappear: Vec<i32>) -> Vec<i32> {
61 vec![]
62 }
63}
64
65// submission codes end
66
67#[cfg(test)]
68mod tests {
69 use super::*;
70
71 #[test]
72 fn test_3112() {
73 }
74}
75
Back
© 2025 bowen.ge All Rights Reserved.