743. Network Delay Time Medium
1/**
2 * [743] Network Delay Time
3 *
4 * You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (ui, vi, wi), where ui is the source node, vi is the target node, and wi is the time it takes for a signal to travel from source to target.
5 * We will send a signal from a given node k. Return the minimum time it takes for all the n nodes to receive the signal. If it is impossible for all the n nodes to receive the signal, return -1.
6 *
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2019/05/23/931_example_1.png" style="width: 217px; height: 239px;" />
9 * Input: times = [[2,1,1],[2,3,1],[3,4,1]], n = 4, k = 2
10 * Output: 2
11 *
12 * Example 2:
13 *
14 * Input: times = [[1,2,1]], n = 2, k = 1
15 * Output: 1
16 *
17 * Example 3:
18 *
19 * Input: times = [[1,2,1]], n = 2, k = 2
20 * Output: -1
21 *
22 *
23 * Constraints:
24 *
25 * 1 <= k <= n <= 100
26 * 1 <= times.length <= 6000
27 * times[i].length == 3
28 * 1 <= ui, vi <= n
29 * ui != vi
30 * 0 <= wi <= 100
31 * All the pairs (ui, vi) are unique. (i.e., no multiple edges.)
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/network-delay-time/
37// discuss: https://leetcode.com/problems/network-delay-time/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn network_delay_time(times: Vec<Vec<i32>>, n: i32, k: i32) -> i32 {
43 0
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_743() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.