#P8935. [JRKSJ R7] 茎

    ID: 9783 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2023洛谷原创O2优化背包 DP树形 DP

[JRKSJ R7] 茎

Problem Description

You are given a rooted tree with nn nodes, where the root is node 11. Now you want to prune this tree. Each time, you may choose a node uu that has not been pruned yet, and then prune all nodes in the subtree of uu (including uu itself). The process stops if and only if you prune node 11.

You know that the path from 11 to xx is the “stem” of this tree and needs special handling. Therefore, at the kk-th pruning, you must perform the operation on xx (rather than just pruning it indirectly). In other words, you are not allowed, at the kk-th pruning or any earlier pruning, to perform the operation on any ancestor of xx so that xx gets pruned together.

Compute how many different operation sequences there are. Two operation sequences are different if and only if their lengths are different, or there exists an operation ii such that the chosen uu at the ii-th step is different. Output the answer modulo 109+710^9+7.

Input Format

The first line contains three integers n,k,xn,k,x. The next n1n-1 lines each contain two integers u,vu,v, representing an edge (u,v)(u,v) in the tree.

Output Format

Output one integer, the answer modulo 109+710^9+7.

3 2 2
1 2
1 3
1
5 2 4
1 2
1 3
2 4
2 5
9
5 1 4
1 2
1 3
2 4
2 5
12

Hint

Sample Explanation

For sample 11, there is only one valid sequence of operations: the first operation chooses 33, the second chooses 22, and the third chooses 11.

For sample 22, the valid operation sequences are: $\{3,4,1\},\{3,4,2,1\},\{3,4,5,1\},\{3,4,5,2,1\},\\ \{5,4,1\},\{5,4,2,1\},\{5,4,2,3,1\},\{5,4,3,1\},\{5,4,3,2,1\}$.

Constraints

This problem uses bundled testdata.

Subtask\text{Subtask} nn\le Special Property Score\text{Score}
11 77 None 55
22 1717 1010
33 5050 A\text A 55
44 None 1515
55 500500 A\text A 55
66 B\text B
77 C\text C 1010
88 None 4545

Special property A\text A: guaranteed that k=1k=1.
Special property B\text B: guaranteed that x=1x=1.
Special property C\text C: guaranteed that i[1,n1],i\forall i\in[1,n-1],i has an edge with i+1i+1.

For 100%100\% of the testdata, 1k,xn5001\le k,x\le n\le 500.

Translated by ChatGPT 5