Network Delay Time
Directed edges [u,v,w] take w time units to deliver a signal. Starting at node k at time zero, return the earliest time by which all n nodes have received it, or -1 if some cannot.
Example 1
times = [[1,2,4],[1,3,9],[2,3,2]]
n = 3
k = 16Explanation
Node 2 receives at 4 and node 3 at 6 via node 2, beating the direct weight 9.
Example 2
times = [[1,2,1]]
n = 2
k = 2-1Explanation
Starting at 2 cannot follow the edge pointing from 1 to 2, leaving 1 unreachable.
Example 3
times = []
n = 1
k = 10Explanation
The sole start node receives at time zero.
Constraints
- 1 <= n <= 100
- Labels are 1..n
- Weights are 0..100
- Directed edges are distinct
Function contract
networkDelayTimeArguments: json, json, jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[[1,2,4],[1,3,9],[2,3,2]]31