Banner Home Page Web Contests Problems Ranklist Status Statistics

Tree

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 60000/30000K (Java/Other)
Total Submission(s) : 0   Accepted Submission(s) : 0
Problem Description
Consider a tree with N vertices, numbered from 1 to N. Add, if it is possible, a minimum number of edges thus every vertex belongs to exactly one cycle.
 

Input
The input has the following structure: <br>N <br>x(1) y(1) <br>x(2) y(2) <br>... <br>x(N-1) y(n-1) <br>N (3 <= N <=100) is the number of vertices. x(i) and y(i) (x(i), y(i) are integers, 1 <= x(i), y(i) <= N) represent the two vertices connected by the i-th edge. <br>
 

Output
The output will contain the value -1 if the problem doesn't have a solution, otherwise an integer, representing the number of added edges.
 

Sample Input
7 1 2 1 3 3 5 3 4 5 6 5 7
 

Sample Output
2
 

Source
PKU
 

Statistic | Submit | Back