Signal arrival time
A signal starts at server source in a network of n servers labelled 1 to n. Each entry of links is [u, v, ms]: a one-way link that carries the signal from u to v in ms milliseconds. A server forwards the signal on all its outgoing links as soon as it first receives it. Return how many milliseconds pass until every server has the signal, or -1 if some server never gets it.
Latencies are non-negative integers; the same link may appear twice.
Besides the tests, one large input (1,000 servers, 10,000 links) with a ~200 ms limit (scaled to your device's speed): brute force won't pass.
Examples
arrival_time(4, [[2,1,1],[2,3,1],[3,4,1]], 2)→2arrival_time(3, [[1,2,10],[1,3,1],[3,2,2]], 1)→3arrival_time(2, [[1,2,1]], 2)→-1