No.2677 Minmax Independent Set
Problem Statement
eoeo and NokonoKotlin play a game using a tree with $N$ vertices. The vertices of the tree are numbered $1, 2, \dots, N$, and all of them are painted white.
In this game, each of the following steps is performed exactly once.
- eoeo chooses any $1$ vertex and paints it black.
- NokonoKotlin chooses $0$ or more vertices painted white and paints them black. However, the vertices must be chosen so that, including the vertex painted in step 1, no two vertices that are finally painted black are adjacent.
When eoeo and NokonoKotlin each play optimally according to the following policies, how many vertices are painted black at the end of the game?
- eoeo minimizes the number of vertices painted black at the end of the game.
- NokonoKotlin maximizes the number of vertices painted black at the end of the game.
Input
The input is given from standard input in the following format. Each $u_i, v_i$ indicates that vertices $u_i, v_i$ are adjacent in the tree.
$N$
$u_1$ $v_1$
$u_2$ $v_2$
$\vdots$
$u_{N-1}$ $v_{N-1}$
Output
Print "the number of vertices painted black at the end of the game" on a single line to standard output, followed by a newline.
Constraints
The input satisfies the following constraints.
- All inputs are integers
- $1 \leq N \leq 2 \times 10^5$
- $1 \leq u_i < v_i \leq N \ (1 \leq i \leq N-1)$
- If $i \neq j$, then $(u_i, v_i) \neq (u_j, v_j)$
- The given graph is a tree
Sample
Sample 1
Input
5 1 2 1 3 1 4 4 5
Output
2
In this case, eoeo paints vertex $1$, and NokonoKotlin paints vertex $5$.
Sample 2
Input
4 1 2 1 3 1 4
Output
1
In this case, eoeo paints vertex $1$, and NokonoKotlin cannot paint any vertex.
Sample 3
Input
9 1 2 2 3 3 4 3 5 3 6 3 7 7 8 7 9
Output
4
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
Xelmeph
null
ngtkana
eoeo