#P8352. [SDOI/SXOI2022] 小 N 的独立集
[SDOI/SXOI2022] 小 N 的独立集
Problem Description
Little N likes the maximum weight independent set problem.
One day, he received a series of tasks for creating problems, so he conveniently created a series of maximum weight independent set problems.
To generate testdata for this whole series at the same time, Little N generated a tree with vertices and chose a positive integer . Then, every time he generates one test case, he only needs to randomly generate an integer vertex weight between for each vertex, and he can obtain a new maximum independent set problem.
Little N gave these problems to his good friend, Little Ω. Little Ω said that there were too many problems and they were too messy, so he planned to classify and process all problems. A natural idea is to classify them by the answer (that is, the sum of vertex weights in a maximum weight independent set). Obviously, the answers to these maximum weight independent set problems must be between , so Little Ω only needs to manage all problems by splitting them into categories according to the answer.
Before Little N officially starts creating problems, Little Ω first needs to compute exactly how many problems there are in each category. After a rough estimate, Little Ω quickly realized that he did not have the kind of memory described in Shiyun, so he firmly rejected Little N’s suggestion of “generate all possible problems first and then slowly classify and count them”. Then, tragically, he realized that he could not compute these numbers either.
He wants you to help him solve this problem. He also said that if you successfully solve it, then when Little N releases those maximum weight independent set problems, he will help you submit a reference solution code.
Input Format
The first line contains positive integers , .
The next lines each contain positive integers , , describing an edge connecting vertices and . It is guaranteed that these edges form a tree.
Output Format
Output lines, each containing one integer. The -th integer indicates, among all possible problems, how many have a maximum weight independent set total weight equal to , modulo .
4 2
1 2
2 3
2 4
0
0
2
6
6
2
0
0
Hint
Sample Explanation
There are a total of maximum weight independent set problems that satisfy the statement.
It can be proven that when the weights of vertices , , and are all , the maximum weight independent set has total weight , and there are such problems. When exactly one of the weights of vertices , , and is , the maximum weight independent set has total weight , and there are such problems. The cases where the maximum weight independent set has total weight or are similar.
Constraints
For of the testdata, ;
For of the testdata, ;
For of the testdata, ;
For another of the testdata, ;
For another of the testdata, ;
For of the testdata, , , .
Hint
The maximum weight independent set problem means: choose a set of vertices such that no two chosen vertices are directly connected by an edge, and the sum of the chosen vertices’ weights is maximized.
Translated by ChatGPT 5