Problems
Tree with small distances
Tree with small distances
You are given an undirected tree consisting of $n$ vertices. An undirected tree is a connected graph with $n − 1$ edges.
Your task is to add the minimum number of edges in such a way that the length of the shortest path from vertex $1$ to any other vertex is at most $2$. Note that you are not allowed to add loops or multiple edges.
\InputFile
The first line contains one integer $n\:(2 \le n \le 2 \cdot 10^5)$ --- the number of vertices in the tree.
The next $n − 1$ lines describe the edges: the $i$-th edge is specified as a pair of vertices $u_i, v_i\:(1 \le u_i, v_i \le n)$. It is guaranteed that the given graph is a tree. It is guaranteed that there are no loops or multiple edges among the given edges.
\OutputFile
Print a single integer --- the minimum number of edges that need to be added in order to ensure that the length of the shortest path from vertex $1$ to any other vertex does not exceed $2$. Note that you cannot add loops or multiple edges.
\includegraphics{https://static.e-olymp.com/content/ba/bab3f0a5d883f8af999f2242f931f02ea7ec5b9b.gif}
Input example #1
7 1 2 2 3 2 4 4 5 4 6 5 7
Output example #1
2
Input example #2
7 1 2 1 3 2 4 2 5 3 6 1 7
Output example #2
0