n servers numbered 0 to n - 1. Each pair links[i] = [u, v] is a two-way channel between servers u and v; any number of messages cross a channel in one second. The network is connected.
Server 0 is the main server and the rest are workers. At the start of second 0, every worker sends a request to the main server. Messages always travel along a shortest path. The main server replies instantly, and the reply travels back along the same path.
Until it gets a reply, worker i resends its request every retry[i] seconds: at seconds retry[i], 2 · retry[i], and so on. The check happens at the start of each second; if the reply has already arrived (including in that very second), no more resends happen. Every copy of the request also reaches the main server and gets its own reply.
Return the earliest second from which no message is moving through or arriving anywhere in the network.links=[[0, 1], [0, 2]], retry=[0, 3, 1] → 4
Both servers are one hop from the main one, so a reply comes back after 2 seconds. Server 1 would resend at second 3, but its reply arrives first. Server 2 resends at second 1, the reply to that copy arrives at second 3, so the network is quiet from second 4.
links=[[0, 1], [1, 2], [2, 3]], retry=[0, 10, 10, 2] → 11
Server 3 is three hops away, so a round trip takes 6 seconds. It sends at seconds 0, 2 and 4, the last reply arrives at second 10, and the network is quiet from second 11. Servers 1 and 2 get their replies before they ever resend.
links=[[0, 1], [0, 2]], retry=[0, 3, 1]
4
Run checks the first 3 tests in your browser. Submit checks all 47 tests on the server, hidden ones included.