Get rid of them all
Easy
Execution time limit is 1 second
Runtime memory usage limit is 64 megabytes
Given a tree with n vertices, your task is to determine the maximum number of edges that can be removed such that every resulting connected component has an even number of vertices.
Input
The first line contains a single integer n (1 ≤ n ≤
10^5
).The following n-1 lines each contain two integers u and v (1 ≤ u, v ≤ n), representing an edge between vertices u and v.
It is guaranteed that the input describes a valid tree.
Output
Print a single integer k, which is the maximum number of edges that can be removed to ensure all connected components have an even number of vertices. If it is not possible to achieve this, print -1.
Examples
Input #1
Answer #1
Input #2
Answer #2
Input #3
Answer #3
Input #4
Answer #4
Submissions 111
Acceptance rate 30%