node_count nodes numbered 1 to node_count. Links are one-way: each entry links[i] = [from, to, delay] means a signal sent from node from arrives at node to after delay time units. There is at most one link for each ordered pair of nodes.
A signal is sent from node source, and every node that receives it immediately forwards it along all of its outgoing links. Return how long it takes until every node in the network has the signal. If some node never gets it, return -1.links=[[1, 2, 4], [1, 3, 1], [3, 2, 2], [2, 4, 1]], node_count=4, source=1 → 4
The signal reaches node 3 after 1, node 2 faster via node 3 after 1 + 2 = 3, and node 4 one unit later, at 4. Node 4 is the last to hear it.
links=[[2, 1, 3]], node_count=3, source=2 → -1
No link leads into node 3, so not every node can be reached.
links=[[1, 2, 4], [1, 3, 1], [3, 2, 2], [2, 4, 1]], node_count=4, source=1
4
Run checks the first 3 tests in your browser. Submit checks all 100 tests on the server, hidden ones included.