atcoder#AGC033C. [AGC033C] Removing Coins
[AGC033C] Removing Coins
Score : points
Problem Statement
Takahashi and Aoki will play a game on a tree. The tree has vertices numbered to , and the -th of the edges connects Vertex and Vertex .
At the beginning of the game, each vertex contains a coin. Starting from Takahashi, he and Aoki will alternately perform the following operation:
- Choose a vertex that contains one or more coins, and remove all the coins from .
- Then, move each coin remaining on the tree to the vertex that is nearest to among the adjacent vertices of the coin's current vertex.
The player who becomes unable to play, loses the game. That is, the player who takes his turn when there is no coin remaining on the tree, loses the game. Determine the winner of the game when both players play optimally.
Constraints
- The graph given as input is a tree.
Input
Input is given from Standard Input in the following format:
Output
Print First
if Takahashi will win, and print Second
if Aoki will win.
3
1 2
2 3
First
Here is one possible progress of the game:
- Takahashi removes the coin from Vertex . Now, Vertex and Vertex contain one coin each.
- Aoki removes the coin from Vertex . Now, Vertex contains one coin.
- Takahashi removes the coin from Vertex . Now, there is no coin remaining on the tree.
- Aoki takes his turn when there is no coin on the tree and loses.
6
1 2
2 3
2 4
4 6
5 6
Second
7
1 7
7 4
3 4
7 5
6 3
2 1
First