#P5281. [ZJOI2019] Minimax搜索
[ZJOI2019] Minimax搜索
Description
Jiutiao Keliansi is a girl who likes playing games. To improve her gaming skills, she wants to arm herself with theory. This problem is related to the famous Minimax search.
Keliansi has a rooted tree with the root numbered . Define the depth of the root as , and the depth of any other node as its parent’s depth plus . Given the values on the leaf nodes, Keliansi defines the value of each non-leaf node as follows:
- For a non-leaf node at odd depth, its value is the maximum among the values of all its children.
- For a non-leaf node at even depth, its value is the minimum among the values of all its children.
At the beginning, Keliansi sets the value of the leaf node numbered to be , and computes the root’s value as .
Now, the evil Cedyks wants to change the root’s value by modifying the values of some leaf nodes. Cedyks has designed a quantum attacker. After it is activated, Cedyks will randomly gain control of a non-empty set of leaf nodes , and can spend some energy to modify the values of the leaf nodes in .
However, modifying leaf node values costs energy. For a leaf node , its initial value is . Suppose Cedyks changes its value to ( can be any integer, including negative numbers). Then the energy needed for this attack is .
Cedyks wants to save as much energy as possible, so he will always complete the attack with the minimum energy, i.e. under the minimum energy cost, make the root’s value change. Let be the energy Cedyks will spend after gaining control of set . In particular, for some sets , no matter how the values of the leaf nodes in are changed, the root’s value will not change. In this case, is defined as . For convenience, we call the stability of .
When there are leaf nodes, there are different non-empty sets of leaf nodes. Before launching the attack, Cedyks wants to estimate the energy he may need. So he gives an interval , and wants to know, for each , how many sets satisfy .
Input Format
The first line contains three integers .
The next lines each contain two integers , indicating an edge in the tree.
Output Format
Output one line with integers. The -th integer indicates how many sets have . The answer may be very large; output it modulo .
5 1 5
1 5
1 4
5 3
5 2
4 0 1 0 2
Hint
Explanation of Sample 1
At the beginning, under Keliansi’s setting (the value of leaf node is ), the root’s value is .
There are leaf nodes in the tree, and there are non-empty sets of leaf nodes, among which:
- have stability . As long as you slightly modify the value of leaf node , the root’s value will change.
- have stability , because the value at node is the smaller one between and . If you only modify node or only modify node , the value at node is always less than or equal to , so the root’s value is always .
- has stability . To make the root’s value change, the value at node must be greater than , so both and must be greater than . Therefore the stability is . One feasible plan is to set both and to .
Constraints
| Test Point | Other Constraints | Test Point | Other Constraints | ||
|---|---|---|---|---|---|
| None | |||||
For all testdata, it is guaranteed that , .
Translated by ChatGPT 5
京公网安备 11011102002149号