問題一覧 > 通常問題

No.806 Turning a Tree into a Path

レベル : / AI推定難易度 : 950 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 355
作問者 : sinsincoscos / テスター : keymoon
お気に入りにしたユーザー ProblemId : 2507 / 自分の提出
問題文最終更新日: 2019-03-22 21:06:30
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 209 (順位表) の他の問題:

Problem Statement

umg has an undirected tree with $N$ vertices. The $i$-th edge connects vertices $a_i$ and $b_i$, and we denote it as edge $(a_i,b_i)$. He can perform the following operation.
Operation: Choose three distinct vertices $u,v,w$ and change edge $(u,v)$ to edge $(u,w)$.
umg wants to perform this operation some number of times to turn his tree into a path. A path is an undirected tree that has exactly two vertices of degree 1.
Find the minimum number of operations umg needs to achieve his goal.

Input

$N$
$a_1\ b_1$
$\vdots$
$a_{N-1}\ b_{N-1}$

$3\le N \le 10^5$
$1\le a_i , b_i \le N$
The given graph is a tree.
For $i\neq j$, $(a_i,b_i)\neq (a_j,b_j)$.

Output

Output the answer on a single line. Print a newline at the end.

Sample

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

You can achieve the goal by changing edge $(2,1)$ to edge $(2,4)$.

Sample 2
Input
3
1 2
2 3
Output
0

The tree is already a path from the start, so no operations are needed.

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