問題一覧 > 通常問題

No.1582 Vertexes vs Edges

レベル : / AI推定難易度 : 1800 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 82
作問者 : magsta / テスター : butsurizuki
お気に入りにしたユーザー ProblemId : 5739 / 自分の提出
問題文最終更新日: 2021-08-19 18:21:53
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. Back to the original
yukicoder contest 302 (順位表) の他の問題:

Problem Statement

You are given a tree with $N$ vertices. The vertices of the tree are numbered from $1$ to $N$, and the edges are numbered up to $N-1$.

Edge $i$ connects vertices $u_i, v_i$. Initially, all vertices are painted white.


A-kun and B-kun play a game using this tree.

A-kun performs A-kun's operation below, and B-kun performs B-kun's operation below. The two of them perform these operations alternately. A-kun goes first.

A-kun's operation
Choose one edge whose 2 connected vertices are both painted white, and paint both of those vertices black.

B-kun's operation
Choose one vertex painted black, and paint that vertex white.

These operations are repeated alternately until A-kun can no longer perform his operation (that is, when, at the time A-kun is to perform his operation, there is no edge whose 2 connected vertices are both painted white).


A-kun tries to make the final number of vertices painted black as large as possible, and B-kun tries to make the final number of vertices painted white as large as possible.

Find the number of vertices that are painted black in the end.

Input

$N$
$u_1\ \ v_1$
$u_2\ \ v_2$
$:$
$u_{N-1}\ \ v_{N-1}$

  • $2 \leq N \leq 10^5$
  • $1 \leq u_i, v_i \leq N$
  • $u_i \neq v_i$
  • All input values are integers
  • The graph represented by the input is a tree

Output

Print the computed value, followed by a newline.

Sample

Sample 1
Input
4
1 2
1 3
1 4
Output
1

First, with A-kun's first operation, vertex 1 and one other vertex are always painted black.

In B-kun's next operation, he paints the black vertex that is not vertex 1 white.

Then A-kun can no longer perform his operation, and the final number of vertices painted black is 1.


Also, if B-kun paints a vertex other than vertex 1 white in his operation, the final number of vertices painted black becomes 2 or more.

Therefore, the answer is 1.

Sample 2
Input
2
1 2
Output
1

Sample 3
Input
12
1 7
8 2
3 12
6 7
7 11
9 1
4 10
12 2
10 1
1 2
5 10
Output
5

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。