Under construction

Still being built. Things may change

Towns

Time limit1sMemory limit1536 MB

Summary
Given a tree of N small towns and hidden large cities with positive edge lengths, find the hub minimizing the farthest-town distance using limited distance queries.
Level

Hard9 of 10

Topics
Tree, Divide and conquer, Implementation
Solved
No attempts yet

Problem

Kazakhstan has NN small towns numbered from 0 through N−1N-1. It also has some number of large cities, and the count is not given. Small towns and large cities together are called settlements.

All settlements are connected by one network of bidirectional highways. Each highway connects two distinct settlements, and each pair of settlements is joined by at most one highway. For any two settlements aa and bb, there is exactly one way to travel from aa to bb without using any highway more than once.

Each small town is directly connected to exactly one other settlement. Each large city is directly connected to three or more settlements.

Every highway has a positive integer length. The distance between two settlements is the smallest total length of highways needed to travel between them.

For a large city CC, let r(C)r(C) be the distance from CC to the small town farthest from CC. A large city is a hub if its r(C)r(C) is the smallest among all large cities. RR is the smallest value of r(C)r(C), which is the distance from a hub to the small town farthest from it.

In the figure, city ff is the only hub, with r(f)=16r(f) = 16, so R=16R = 16. Removing ff splits the network into four pieces containing the small town sets {0, 1, 10}, {2, 3}, {4, 5, 6, 7}, and {8, 9}. No piece has more than ⌊11/2⌋\lfloor 11/2 \rfloor small towns, so ff is a balanced hub.

Removing a hub splits the network into several connected pieces. A hub is balanced if each piece contains at most ⌊N/2⌋\lfloor N/2 \rfloor small towns. Large cities are not counted.

Constraints

6≤N≤1106 \le N \le 110.

The distance between any two distinct small towns is between 1 and 1,000,000 inclusive.

The number of queries your program may make is limited. The limit varies by subtask. If the program exceeds the query limit, it is terminated and the answer is judged incorrect.

Examples1

  1. Example 1

    Input
    6
    0 2 2 2 2 2
    2 0 2 2 2 2
    2 2 0 2 2 2
    2 2 2 0 2 2
    2 2 2 2 0 2
    2 2 2 2 2 0
    
    Expected output
    0