#P10037. 「FAOI-R2」霜雪千年
「FAOI-R2」霜雪千年
Background
Looking back on this old street, in the mist and clouds I trace who I am.
Just a few drops of evening rain are enough to cover up right and wrong.
When the moonlight surges, who will gently knock on this door?
Moss-green bluestone slabs, mottled with years flowing like water.
A few small cups of wine, yet the tangled knot cannot be sorted out.
In your indifferent brows, I glimpse the joys and sorrows of those who part, frosted by snow.
Luo Tianyi sees a pear tree in the snow. There is limited energy in the root of the pear tree, and it can transmit energy upward to other nodes. But the wind and snow are heavy: at every moment, the energy at each node may increase or decrease, and nodes with too little energy will fall off.
Problem Description
Specifically, this pear tree can be abstracted as a tree rooted at node . Initially, every node is white. Each node has energy . Initially, the energy of all nodes except is , and . We define an accumulated energy .
We define the value of a sequence through the following process:
- Pass through the moments in increasing order.
- At moment , perform .
- For an edge in the tree, with as the parent, you may choose an integer and perform , . After that, within this moment, edges of the form where is the parent cannot be operated on.
- If a node satisfies , dye node and all nodes in the subtree of black.
- Perform optimal operations to maximize the number of white nodes after moment . The value of this sequence is this maximum number of white nodes.
A sequence is defined to be valid if and only if , . Given , compute the sum of the values of all valid sequences modulo .
Input Format
The first line contains four non-negative integers , representing the number of nodes in the tree, the range of values of , the number of moments, and the initial value of , respectively.
The next lines each contain two positive integers , indicating that there is an edge between node and node .
Output Format
Output the sum of the values of all valid sequences modulo .
1 1 1 1
3
3 1 2 2
1 2
1 3
22
5 2 3 5
1 2
2 3
2 4
4 5
407
10 5 6 44
1 2
1 3
2 5
2 6
3 4
6 7
6 8
4 9
9 10
10465095
Hint
[Sample #3 Explanation]
For one case , one optimal set of operations is as follows:
- At the first moment, node transfers energy to node . After the operation, , .
- At the second moment, node transfers energy to node . After the operation, , .
- At the third moment, node transfers energy to node , and node transfers energy to node . After the operations, , .
- After all moments end, since there is never any node with , all nodes are white.
[Sample #4 Explanation]
For one case , one optimal set of operations is as follows:
- During moments , perform no operations.
- After all moments end, since there is never any node with , all nodes are white.
[Constraints]
This problem uses bundled testdata.
| Subtask ID | Score | Special Property | ||||
|---|---|---|---|---|---|---|
| × | ||||||
| × | ||||||
Special property: the shape of the tree is guaranteed to be a "chrysanthemum" (juhua).
For of the testdata, , , , , and the input is guaranteed to form a tree.
[Others]
The original name of this problem was Pear Blossoms Bloom. Since the statement had errors during the contest and the original statement was not very readable, the statement was rewritten and renamed in March 2024. Renaming the title made it inconvenient for contestants to find this problem again during the contest, but the problem setter realized it only after a long time, so it was not convenient to change it back. We apologize for this.
In August 2025, the term "heat" in the statement was changed to "energy".
Translated by ChatGPT 5