#P17076. [ICPC 2017 Shenyang R] Tree

    ID: 16739 Type: RemoteJudge 1000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 6 Uploaded By: Tags>图论2017深度优先搜索 DFS树形 DPICPC

[ICPC 2017 Shenyang R] Tree

题目描述

Consider a un-rooted tree TT which is not the biological significance of tree or plant, but a tree as an undirected graph in graph theory with nn nodes, labelled from 1 to nn. If you cannot understand the concept of a tree here, please omit this problem.

Now we decide to colour its nodes with kk distinct colours, labelled from 1 to kk. Then for each colour i=1,2,⋯ ,ki = 1, 2, \cdots, k, define EiE_i as the minimum subset of edges connecting all nodes coloured by ii. If there is no node of the tree coloured by a specified colour ii, EiE_i will be empty.

Try to decide a colour scheme to maximize the size of E1∩E2∩⋯∩EkE_1 \cap E_2 \cap \cdots \cap E_k, and output its size.

输入格式

The first line of input contains an integer TT (1≤T≤10001 \le T \le 1000), indicating the total number of test cases.

For each case, the first line contains two positive integers nn which is the size of the tree and kk (k≤500k \le 500) which is the number of colours. Each of the following n−1n - 1 lines contains two integers xx and yy describing an edge between them. We are sure that the given graph is a tree.

The summation of nn in input is smaller than or equal to 200000200000.

输出格式

For each test case, output the maximum size of E1∩E2∩⋯∩EkE_1 \cap E_2 \cap \cdots \cap E_k.

3
4 2
1 2
2 3
3 4
4 2
1 2
1 3
1 4
6 3
1 2
2 3
3 4
3 5
6 2
1
0
1