Network Delay Time
You are given a directed weighted graph of n nodes labeled 1..n and a list times where times[i] = (u, v, w) means a signal takes w time to travel from node u to node v. A signal starts at node k. Return the minimum time for all n nodes to receive the signal, or -1 if some node can never receive it.
Open official problem prompt ↗Find how long it takes for a signal broadcast from node k to reach the farthest node, i.e. the longest of all shortest paths from k.
Like ripples spreading from a stone dropped in a pond: the whole surface is 'covered' only when the ripple reaches the most distant edge.
- Input
- times = [[2,1,1],[2,3,1],[3,4,1]], n = 4, k = 2
- Output
- 2
- Why
- From node 2 the signal reaches 1 in time 1, 3 in time 1, and 4 via 3 in time 2; the slowest arrival is 2.
1 <= k <= n <= 1001 <= times.length <= 6000times[i] = (u_i, v_i, w_i)1 <= u_i, v_i <= nu_i != v_i0 <= w_i <= 100All (u_i, v_i) pairs are unique