#P7728. 旧神归来(Return of Them)
旧神归来(Return of Them)
Background
With the decisive battle between the phantom and the shadow, the completion of the Moon Island altar, the appearance of the celestial storm, and the arrival of the heavenly guardians, all secrets of the Moon and ancient times seem to have reached the final chapter.
The old gods are about to return.
Problem Description
An ordinary tree on Moon Island keeps growing under the erosion of moonlight, and becomes even more uncontrolled as the lunar storm arrives.
Specifically, the growth rules are as follows:
-
Initially, there is a rooted tree with nodes, rooted at .
-
On day , the tree grows from into . The rule is: let be a leaf node in with the minimum depth (if there are multiple, choose any one). Replace the node with itself.
In this problem, the depth of a node is defined as the number of edges on the simple path from it to the root node. Note that this may differ from the usual definition.
The figure below shows an example of growing from to :

Besides dealing with the heavenly guardians, it is also important to estimate environmental effects, so you need to compute:
- For each integer , find , the minimum number of days such that, in , the minimum depth among all leaf nodes is greater than .
Output the answers modulo .
Input Format
The first line contains two integers , representing the number of nodes in and the depth range for which answers are required.
In the next lines, each line contains two integers , indicating that there is an edge between nodes and in .
Output Format
Output lines. On the -th line, output one integer representing .
4 10
1 2
2 3
1 4
1
3
4
7
9
12
16
24
32
45
Hint
[Sample 1 Explanation]
The figure shows the shapes of to . The shallowest leaf is marked in red, and the part grown in the most recent operation is marked in blue.
You can see that, in , the minimum leaf depth is greater than ; in , the minimum leaf depth is greater than ; and after one more operation, in , the minimum leaf depth will be greater than (it should be ). This explains the first three lines of the sample output:

[Constraints]
This problem uses bundled testdata.
For of the testdata: .
| Subtask ID | Score | Special Constraint | |
|---|---|---|---|
| is a binary tree | |||
| is a chain with as an endpoint | |||
| is a binary tree, and every non-leaf node has two children | |||
| None | |||

Translated by ChatGPT 5