Asked at
Network Delay Time
MediumVerifiedDijkstraHeapBFS~25 min
A signal starts at node k and propagates along directed edges. Each times[i] = [u, v, w] means the signal travels from u to v in w time. Nodes are labelled 1..n.
Return the minimum time for all n nodes to receive the signal, or -1 if some node is unreachable.
The input arrives as a single object { times, n, k }.
Examples
in{ times: [[2,1,1],[2,3,1],[3,4,1]], n: 4, k: 2 }
out2
From node 2 the farthest node (4) is reached at time 2.
in{ times: [[1,2,1]], n: 2, k: 2 }
out-1
Node 1 is never reached from node 2.
Constraints
- 1 ≤ n ≤ 100
- 1 ≤ k ≤ n
- Edges are directed: times[i] = [u, v, w]
- 0 ≤ w ≤ 100
Get help
🔑
Sign in to solve
Sign in to write, run, and submit your solution — and to pick up where your iOS flow left off.