311186: CF1946C. Tree Cutting

Memory Limit:512 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Tree Cuttingtime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output

You are given a tree with $n$ vertices.

Your task is to find the maximum number $x$ such that it is possible to remove exactly $k$ edges from this tree in such a way that the size of each remaining connected component$^{\dagger}$ is at least $x$.

$^{\dagger}$ Two vertices $v$ and $u$ are in the same connected component if there exists a sequence of numbers $t_1, t_2, \ldots, t_k$ of arbitrary length $k$, such that $t_1 = v$, $t_k = u$, and for each $i$ from $1$ to $k - 1$, vertices $t_i$ and $t_{i+1}$ are connected by an edge.

Input

Each test consists of several sets of input data. The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of sets of input data. This is followed by a description of the sets of input data.

The first line of each set of input data contains two integers $n$ and $k$ ($1 \le k < n \le 10^5$) — the number of vertices in the tree and the number of edges to be removed.

Each of the next $n - 1$ lines of each set of input data contains two integers $v$ and $u$ ($1 \le v, u \le n$) — the next edge of the tree.

It is guaranteed that the sum of the values of $n$ for all sets of input data does not exceed $10^5$.

Output

For each set of input data, output a single line containing the maximum number $x$ such that it is possible to remove exactly $k$ edges from the tree in such a way that the size of each remaining connected component is at least $x$.

ExampleInput
6
5 1
1 2
1 3
3 4
3 5
2 1
1 2
6 1
1 2
2 3
3 4
4 5
5 6
3 1
1 2
1 3
8 2
1 2
1 3
2 4
2 5
3 6
3 7
3 8
6 2
1 2
2 3
1 4
4 5
5 6
Output
2
1
3
1
1
2
Note

The tree in the first set of input data:

After removing the edge $1$ — $3$, the tree will look as follows:

The tree has split into two connected components. The first component consists of two vertices: $1$ and $2$. The second connected component consists of three vertices: $3, 4$ and $5$. In both connected components, there are at least two vertices. It can be shown that the answer $3$ is not achievable, so the answer is $2$.

Output

题目大意:给定一棵有n个顶点的树,需要找出最大的数x,使得可以恰好移除k条边,使得每个剩余的连通分量的大小至少为x。

输入数据格式:每个测试包含多组输入数据。第一行包含一个整数t(1≤t≤10^4)——输入数据组数。接下来是输入数据组的描述。每组输入数据的第一行包含两个整数n和k(1≤k
输出数据格式:对于每组输入数据,输出一个包含最大数x的行,使得可以恰好移除k条边,使得每个剩余的连通分量的大小至少为x。

示例:

输入:
```
6
5 1
1 2
1 3
3 4
3 5
2 1
1 2
6 1
1 2
2 3
3 4
4 5
5 6
3 1
1 2
1 3
8 2
1 2
1 3
2 4
2 5
3 6
3 7
3 8
6 2
1 2
2 3
1 4
4 5
5 6
```

输出:
```
2
1
3
1
1
2
```题目大意:给定一棵有n个顶点的树,需要找出最大的数x,使得可以恰好移除k条边,使得每个剩余的连通分量的大小至少为x。 输入数据格式:每个测试包含多组输入数据。第一行包含一个整数t(1≤t≤10^4)——输入数据组数。接下来是输入数据组的描述。每组输入数据的第一行包含两个整数n和k(1≤k

加入题单

上一题 下一题 算法标签: