atcoder#AGC010F. [AGC010F] Tree Game
[AGC010F] Tree Game
Score : points
Problem Statement
There is a tree with vertices, numbered through . The -th of the edges connects vertices and .
Currently, there are stones placed on vertex . Takahashi and Aoki will play a game using this tree.
First, Takahashi will select a vertex and place a piece on it. Then, starting from Takahashi, they will alternately perform the following operation:
- Remove one stone from the vertex currently occupied by the piece.
- Then, move the piece to a vertex that is adjacent to the currently occupied vertex.
The player who is left with no stone on the vertex occupied by the piece and thus cannot perform the operation, loses the game. Find all the vertices such that Takahashi can place the piece on at the beginning and win the game.
Constraints
- The given graph is a tree.
Input
The input is given from Standard Input in the following format:
…
:
Output
Print the indices of the vertices such that Takahashi can place the piece on at the beginning and win the game, in a line, in ascending order.
3
1 2 3
1 2
2 3
2
The following is one possible progress of the game when Takahashi places the piece on vertex :
- Takahashi moves the piece to vertex . The number of the stones on each vertex is now: .
- Aoki moves the piece to vertex . The number of the stones on each vertex is now: .
- Takahashi moves the piece to vertex . The number of the stones on each vertex is now: .
- Aoki cannot take a stone from the vertex, and thus Takahashi wins.
5
5 4 1 2 3
1 2
1 3
2 4
2 5
1 2
3
1 1 1
1 2
2 3
Note that the correct output may be an empty line.