Time limit
2s
Memory limit
128 MB
While cleaning a garden, Sangwook found a tree that had grown into a messy shape. It is time to prune it.
The garden tree is represented as a connected graph with n vertices and n - 1 edges. Each vertex is a leaf of the garden tree, and each edge is a branch.
Sangwook wants to prune the tree so that exactly m vertices remain. One pruning operation cuts one edge in the currently kept tree. When the cut splits the graph into two connected components, he keeps one component and discards the other.
Given the shape of the tree, find the minimum number of pruning operations needed to finish the job.
The first line contains n and m (1 <= n <= 150, 1 <= m <= n).
Each of the next n - 1 lines contains two vertex numbers describing one branch of the tree. The two numbers mean that there is an edge connecting those vertices. Vertex numbers are integers from 1 to n.
Print the minimum number of pruning operations. If it is impossible, print -1.
For the public test, cutting edges 1-4 and 1-5 leaves a tree with the desired size.