#P16309. [ICPC 2023 Jinan R] 图划分 2
[ICPC 2023 Jinan R] 图划分 2
Problem Description
After successfully solving the problem Cut Cut Cut!, Xiaoqingyu wants to further improve his ability to partition a graph into connected components.
One day, a mysterious wise man asked Xiaoqingyu a question. In this problem, Xiaoqingyu is given an unrooted tree with nodes and an integer . Let be the set of all edges in the tree. Xiaoqingyu needs to find a subset such that after removing all edges in , the graph is split into several connected components, and the size of each connected component is either or .
Of course, as a master of splitting things, Xiaoqingyu solved this problem easily. But the wise man wanted more than that. He not only wanted to find one solution, but also to know all possible results. Therefore, he asked Xiaoqingyu to compute how many ways there are to choose that satisfy the condition above. Two solutions are considered different if the chosen edge subsets are different.
Please help Xiaoqingyu complete this challenge. Since the answer may be very large, you only need to output the result modulo .
Input Format
There are multiple testcases. The first line contains an integer denoting the number of testcases. For each testcase:
The first line contains two integers and (, ), representing the number of nodes in the tree and the target size of the smaller connected components.
In the next lines, the -th line contains two integers and (), representing an edge connecting nodes and .
It is guaranteed that the sum of over all testcases does not exceed .
Output Format
For each testcase, output one line containing one integer, representing the number of ways to choose the subset modulo .
2
8 2
1 2
3 1
4 6
3 5
2 4
8 5
5 7
4 3
1 2
1 3
2 4
2
1
Hint
Let denote an edge connecting nodes and . For the first sample, two valid edge subsets are and .
Translated by ChatGPT 5