We’re preparing your current view and syncing the latest data.
You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (u, v, w), where u is the source node, v is the target node, and w is the time it takes for a signal to travel from u to v. You send a signal from a given node k. Return the time it takes for all the n nodes to receive the signal. If it is impossible for all the nodes to receive the signal, return -1.
Integer representing the time it takes for all nodes to receive the signal or -1 if impossible.
Example 1
Input
n = 4, times = [[2,1,1],[2,3,1],[3,4,1]], k = 2
Output
2
Explanation
Starting from node 2, the signal reaches node 1 in 1 unit, node 3 in 1 unit, and then node 4 in 2 units. The maximum time to reach all nodes is 2.