#P16309. [ICPC 2023 Jinan R] 图划分 2

    ID: 18245 远端评测题 3000ms 1024MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>动态规划 DP2023树形 DPICPC根号分治济南

[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 nn nodes and an integer kk. Let EE be the set of all edges in the tree. Xiaoqingyu needs to find a subset EEE' \subseteq E such that after removing all edges in EE', the graph is split into several connected components, and the size of each connected component is either kk or (k+1)(k+1).

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 EEE' \subseteq E 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 998244353998\,244\,353.

Input Format

There are multiple testcases. The first line contains an integer TT denoting the number of testcases. For each testcase:

The first line contains two integers nn and kk (2n1052 \le n \le 10^5, 1kn1 \le k \le n), representing the number of nodes in the tree and the target size of the smaller connected components.

In the next (n1)(n - 1) lines, the ii-th line contains two integers uiu_i and viv_i (1ui,vin1 \le u_i, v_i \le n), representing an edge connecting nodes uiu_i and viv_i.

It is guaranteed that the sum of nn over all testcases does not exceed 3×1053 \times 10^5.

Output Format

For each testcase, output one line containing one integer, representing the number of ways to choose the subset EE' modulo 998244353998\,244\,353.

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 (u,v)(u, v) denote an edge connecting nodes uu and vv. For the first sample, two valid edge subsets are {(2,4),(3,5)}\{(2, 4), (3, 5)\} and {(1,2),(3,5)}\{(1, 2), (3, 5)\}.

Translated by ChatGPT 5