Network delay time
Mediumgraphdijkstraheapshortest path
There are n devices numbered 0 to n-1. Each [u, v, w] in times means a message from u to v takes w seconds (one way). A message starts at device k. Return the time when every device has received it, or -1 if some device is never reached.
Example 1
Input: times = [[1,0,1],[1,2,1],[2,3,1]], n = 4, k = 1 Output: 2
Example 2
Input: times = [[0,1,1]], n = 2, k = 1 Output: -1
Constraints
- 1 ≤ n ≤ 100
- 1 ≤ times.length ≤ 6000
- 0 ≤ u, v < n, u ≠ v
- 1 ≤ w ≤ 100
- No repeated (u, v) pair
Submit checks your solution against 8 tests, including hidden ones.
/**
* @param {int[][]} times
* @param {int} n
* @param {int} k
* @return {int}
*/
function networkDelay(times, n, k) {
}