JAG Strikes Back
Time limit1sMemory limit128 MB
Two players alternately claim vertices of a tree, and the task is the optimal distance between the two farthest vertices the first player takes.
- Level
Medium7 of 10
- Topics
- Tree, Game theory, BFS
- Solved
- No attempts yet
Problem
JAG is the new revolutionary game from the company . Each game has rounds. In every round, the players get a map of territories. Exactly pairs of territories share a border, and the map is connected: for any two territories and , you can walk from to , possibly crossing other territories.
The players take territories in turns until all territories are chosen. Two rules apply:
- Moves cannot be skipped.
- A player cannot choose a territory that is already chosen by either player.
The distance between territories and is the fewest borders you must cross on a path from to . The first player wants to minimize the distance between the two furthest territories that the first player chose. The second player wants to maximize that distance. Print the distance between the two furthest territories chosen by the first player when both players play optimally.
Input
The first line contains the number of rounds . Each round starts with a line containing (), the number of territories. The next lines each contain two numbers and , meaning territories and share a border. The sum of over all rounds does not exceed 200000.
Output
Print lines. The -th line contains the answer for the -th round.