PT07X - Vertex Cover


You are given an unweighted, undirected tree. Write a program to find a vertex set of minimum size in this tree such that each edge has as least one of its end-points in that set.

Input

The first line of the input file contains one integer N --- number of nodes in the tree (0 < N <= 100000). Next N-1 lines contain N-1 edges of that tree --- Each line contains a pair (u, v) means there is an edge between node u and node v (1 <= u,v <= N).

Output

Print number of nodes in the satisfied vertex set on one line.

Example 1

Input:
3
1 2
1 3

Output:
1

Explanation:
The set can be {1}

Example 2

Input:
3
1 2
2 3

Output:
1

Explanation:
The set can be {2}

hide comments
supriyanta: 2018-08-03 01:51:04

DP on tree

aman_sachin200: 2018-06-15 12:30:21

Nice One!!DP+DFS!!

chetan4060: 2018-04-16 14:48:24

simple dp on trees.

sarwar__05: 2018-02-08 20:37:46

there if no input like:
1

dunjen_master: 2018-01-20 09:51:35

dp+dfs=ac

abhi6991: 2017-09-23 05:40:13

In Cpp not passing graph as a reference resulted in 2 WA.

mamnoonsiam: 2017-07-25 13:07:30

AC in one go :)
easy tree dp... dfs

d_skyhawk: 2017-04-01 06:45:04

DP+Tree=AC in a go

rishi_07: 2017-03-31 15:48:01

Finally AC! Nice DP.

cake_is_a_lie: 2017-03-05 14:44:08

For some reason I understood each vertex needed one neighbour in the output set. That cost me SO many WAs.


Added by:Thanh-Vy Hua
Date:2007-03-28
Time limit:1s-3s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:Co-author Amber