問題一覧 > 通常問題

No.2677 Minmax Independent Set

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 63
作問者 : nu50218 / テスター : Xelmeph null ngtkana NokonoKotlin eoeo
お気に入りにしたユーザー ProblemId : 9536 / 自分の提出
問題文最終更新日: 2024-03-15 21:22:17
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
yukicoder contest 421 (NUPC2023) (順位表) の他の問題:

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.

  1. eoeo chooses any $1$ vertex and paints it black.
  2. 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もしくは右上の雲マークをクリックしてアカウントを作成してください。