problem statement, tree is an undirected associated diagram where there are no cycles. This issue is about non-established trees. A leaf of a tree is a vertex that is associated with all things considered one vertex. The landscaper Vitaly grew a tree from n vertices. He chose to manage the tree. To do this, he plays out a number of tasks. In
Please c++ only. Correct answer will upvoted else downvoted.
In this problem statement, tree is an undirected associated diagram where there are no cycles. This issue is about non-established trees. A leaf of a tree is a vertex that is associated with all things considered one vertex. The landscaper Vitaly grew a tree from n vertices. He chose to manage the tree. To do this, he plays out a number of tasks. In one activity, he eliminates all leaves of the tree. Note the uncommon instances of the activity: applying an activity to an unfilled tree (of 0 vertices) doesn't transform it.
applying an activity to a tree of one vertex eliminates this vertex this vertex is treated as a leaf. applying an activity to a tree of two vertices eliminates both vertices (both vertices are treated as leaves). Vitaly applied k tasks successively to the tree. What number of vertices remain?
Input :The main line contains one integer t (1≤t≤104) — the number of experiments. Then, at that point, t experiments follow. Each experiment is gone before by an unfilled line.
Each experiment comprises of a few lines. The main line of the experiment contains two integers n and k (1≤n≤4⋅105, 1≤k≤2⋅105) — the number of vertices in the tree and the number of activities, separately. Then, at that point, n−1 lines follow, every one of them contains two integers u and v (1≤u,v≤n, u≠v) which depict a couple of vertices associated by an edge. It is ensured that the given chart is a tree and has no circles or numerous edges. It is ensured that the amount of n from all experiments doesn't surpass 4⋅105.
Output :For each experiment output on a different line a solitary integer — the number of vertices that stay in the tree subsequent to applying k activities.
Step by step
Solved in 4 steps with 1 images