TRAOMBINNAA is going to be Billy Butcher's base for the next season of the boys. He is going to build a forest around it to fool Homlander in case of any attack. As Homlander has weakness staring at similar looking objects, Butcher will build the forest with several -beautiful trees.
Now, you’re given a tree consisting of n nodes. Find the number of nodes needed to make the tree -beautiful, or state that it’s impossible so that Butcher can put away that tree. You can select any node as the root node in this problem. Recall that a tree is a connected acyclic undirected graph with n nodes and edges. A -beautiful tree is such that at least one of its child node has distance from the root and all other child with distance from root less than or equal to . Note that a tree can have several beautiful configurations considering different root node. For clear understanding, look at the given pictures below.
Input starts with (), the number of test cases. The first line of each test case consists of two integers, () and (), the number of nodes in the tree and the required beautiful configuration. Each of the next lines consists of two integers and (), denoting an edge between node and node .
Sum of over all test cases does not exceed .
for each test case, print the minimum number of nodes needed to be added to the tree for making it a -beautiful tree. If it’s impossible to build a -beautiful tree, print “-1” (w/o quotes).
Input | Output |
---|---|
2 7 1 1 2 1 3 1 4 4 5 4 6 6 7 7 7 4 5 4 6 6 7 2 1 3 1 1 4 | -1 3 |