No.768 Tapris and Noel play the game on Treeone
Problem Statement
One day, Noel and Tapris played a game using their friend Treeone.
The game follows the rules below.
- 0. Treeone is a tree with $N$ vertices, with nothing written on any vertex. First, Noel chooses any 1 vertex she likes and writes the letter "N" on it.
- 1. Tapris chooses 1 vertex with nothing written on it from among the vertices adjacent to the vertex on which the letter "N" is written, and writes the letter "T" on it.
- 2. Noel chooses 1 vertex with nothing written on it from among the vertices adjacent to the vertex on which the letter "T" is written, and writes the letter "N" on it.
- 3. Steps 1 - 2 are repeated; the player who can no longer write loses.
Noel wants to beat Tapris.
Find all vertices from which Noel can win regardless of Tapris's choices.
Input
$N$
$a_1\ b_1$
$a_2\ b_2$
$\vdots$
$a_{N-1}\ b_{N-1}$
The first line contains the number of vertices of the tree, $N(2\le N\le 10^5)$.
Each of the following N - 1 lines contains $a_i$ and $b_i(1\le a_i,\ b_i\le N)$ separated by a space, and edge$_i$ connects vertex $a_i$ and vertex $b_i$.
Output
On the first line, output the number of vertices such that Noel wins if she chooses that vertex first.
From the second line onward, output the vertices such that Noel wins if she chooses that vertex first, in ascending order, separated by newlines (output a newline after the last vertex as well).
If there is no such vertex, output 0.
Sample
Sample 1
Input
6 1 2 1 3 2 4 2 5 2 6
Output
3 4 5 6
By choosing vertex 4, 5, or 6, Noel can win no matter which vertices Tapris chooses.
Sample 2
Input
5 1 2 1 5 2 3 3 4
Output
3 2 4 5
Good luck.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
lumc_