medium

Network Delay Time

A network of n nodes has directed edges with positive travel times. A signal is sent from node k. Return how long it takes for every node to receive it, or -1 if some node is unreachable.

Constraints
  • 1 ≤ n ≤ 100
  • 1 ≤ times.length ≤ 6000
  • 1 ≤ w ≤ 100
Examples
in: times = [[2,1,1],[2,3,1],[3,4,1]], n = 4, k = 2
out: 2

Code it yourself

Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?

Choose an approach to check your pattern recognition, or reveal the discussion when you need help.