No.3514 Majority Driven Tree
タグ : / 解いたユーザー数 26
作問者 :
yt142857
/ テスター :
Germanium32
Problem Statement
You are given a tree with $N$ vertices. The $i$-th edge connects vertex $u_i$ and vertex $v_i$ bidirectionally.
Each vertex of the tree is painted either black or white, and initially all vertices are painted white.
Hijiri wants to make all vertices black by performing the following two operations any number of times in any order.
Operation 1: Choose one white vertex and make it black. This costs 1.
Operation 2: Choose one white vertex. If a majority of the vertices adjacent to it are black, make it black. This costs nothing.
Find the minimum cost required to make all vertices black.
Constraints
- $1 \le N \le 100000$
- $1 \le u_i,v_i \le N$
- All inputs are integers
- The given graph is a tree
Input
$N$
$u_1\ v_1$
$u_2\ v_2$
$u_3\ v_3$
$\vdots$
$u_{N-1}\ v_{N-1}$
Output
Output the minimum cost required for Hijiri to make all vertices black.
Sample
Sample 1
Input
8 1 2 1 3 1 4 2 5 2 6 3 7 3 8
Output
2
By painting vertices 2,3 black with Operation 1, and then painting vertices 5,6,7,8,1,4 black in this order with Operation 2, all vertices can be made black at cost 2, and this is the minimum cost.
Sample 2
Input
3 1 2 2 3
Output
1
By painting vertex 2 black with Operation 1 and painting vertices 1,3 black with Operation 2, a cost of 1 can be achieved, and this is the minimum cost.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。