Network Delay Time
Medium
LC #743
dijkstrashortest pathheapNot attempted yet
A network has n nodes labelled 1..n. Each entry
[u, v, w] in times is a directed link: a signal
sent from u reaches v after w time units.
A signal starts at node k. Return the time it takes for
all nodes to receive it, or -1 if some node never
does.
Example 1
Input: times = [[2,1,1],[2,3,1],[3,4,1]],
n = 4, k = 2
Output: 2
Node 4 is reached last: 2 → 3 → 4.
Example 2
Input: times = [[1,2,1]], n = 2, k = 1
Output: 1
Example 3
Input: times = [[1,2,1]], n = 2, k = 2
Output: -1
Links are one-way: node 1 is unreachable from 2.
Constraints
1 <= n <= 10^4,0 <= len(times) <= 3 * 10^40 <= w <= 100- there may be several links between the same pair