You are given a network of servers, numbered from to . The network has links and forms a tree.
Transmitting an entire file through link takes exactly seconds.
Initially, exactly one server has the complete file. File transmissions follow these rules:
For each with , independently suppose that server is the only server that has the file initially. Find the minimum time needed for every server to receive the complete file.
For each test case, output the minimum required time for every possible initially informed server:
The file must cross the only link, which takes seconds, regardless of the starting server.
Starting from an endpoint, the two transmissions take seconds. Starting from server , both links must be used one after the other, so the same total is required.
Starting from server , first send to server and then to server . The two transmissions of length can then overlap, and all servers are informed after seconds. Similar schedules work from servers and . From server or , the file must travel along the full weighted path of length to reach the other endpoint.
Starting from server , send to server first. The transmissions from to and from to can then happen simultaneously, finishing at time . The same is possible from server . From either endpoint, the file must traverse the full path, whose total weight is .