#P10037. 「FAOI-R2」霜雪千年

    ID: 11107 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP数学2024洛谷原创O2优化整除分块

「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 11. Initially, every node is white. Each node has energy aia_i. Initially, the energy of all nodes except 11 is 00, and a1=ka_1=k. We define an accumulated energy bb.

We define the value of a sequence {vt}\{v_t\} through the following process:

  • Pass through the tt moments 1,2,3,,t1,2,3,\dots,t in increasing order.
  • At moment xx, perform bb+vxb\gets b+v_x.
  • For an edge (u,v)(u,v) in the tree, with uu as the parent, you may choose an integer h[0,au]h\in[0,a_u] and perform auauha_u\gets a_u-h, avav+ha_v\gets a_v+h. After that, within this moment, edges of the form (v,w)(v,w) where vv is the parent cannot be operated on.
  • If a node ii satisfies ai+b<0a_i+b<0, dye node ii and all nodes in the subtree of ii black.
  • Perform optimal operations to maximize the number of white nodes after moment tt. The value of this sequence is this maximum number of white nodes.

A sequence {vt}\{v_t\} is defined to be valid if and only if i[1,t]\forall i\in[1,t], vi[0,m]\lvert v_i\rvert\in[0,m]. Given tt, compute the sum of the values of all valid sequences {vt}\{v_t\} modulo 998244353998244353.

Input Format

The first line contains four non-negative integers n,m,t,kn,m,t,k, representing the number of nodes in the tree, the range of values of viv_i, the number of moments, and the initial value of a1a_1, respectively.

The next n1n-1 lines each contain two positive integers u,vu,v, indicating that there is an edge between node uu and node vv.

Output Format

Output the sum of the values of all valid sequences modulo 998244353998244353.

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 {v3}=[1,0,2]\{v_3\}=[1,0,-2], one optimal set of operations is as follows:

  • At the first moment, node 11 transfers 44 energy to node 22. After the operation, a=[1,4,0,0,0]a=[1,4,0,0,0], b=1b=1.
  • At the second moment, node 22 transfers 22 energy to node 44. After the operation, a=[1,2,0,2,0]a=[1,2,0,2,0], b=1b=1.
  • At the third moment, node 22 transfers 11 energy to node 33, and node 44 transfers 11 energy to node 55. After the operations, a=[1,1,1,1,1]a=[1,1,1,1,1], b=1b=-1.
  • After all moments end, since there is never any node with ai+b<0a_i+b<0, all nodes are white.

[Sample #4 Explanation]

For one case {v6}=[1,2,1,2,1,2]\{v_{6}\}=[1,2,1,2,1,2], one optimal set of operations is as follows:

  • During moments 161\sim 6, perform no operations.
  • After all moments end, since there is never any node with ai+b<0a_i+b<0, all nodes are white.

[Constraints]

This problem uses bundled testdata.

Subtask ID nn \le mm \le tt \le kk \le Score Special Property
00 44 4040 2020 ×
11 2×1052 \times 10^5 2020 1×1051 \times 10^5 1010 \checkmark
22 3×1053 \times 10^5 2020 ×
33 5050 100100 1010
44 500500 4040

Special property: the shape of the tree is guaranteed to be a "chrysanthemum" (juhua).

For 100%100\% of the testdata, 1n2×1051\leq n\leq 2\times 10^5, 1k3×1051\leq k\leq 3\times 10^5, 1m501\leq m\leq 50, 1t5001\leq t\leq 500, 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