問題一覧 > 通常問題

No.3514 Majority Driven Tree

レベル : / AI推定難易度 : 1900 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 26
作問者 : yt142857 / テスター : aa36 yu23578 Yoyoyo8128 GaLLium Germanium32
お気に入りにしたユーザー ProblemId : 13121 / 自分の提出
問題文最終更新日: 2026-04-24 21:45:08
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 497 聖光学院プログラミングコンテスト2026 day1 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。