#P8935. [JRKSJ R7] 茎
[JRKSJ R7] 茎
Problem Description
You are given a rooted tree with nodes, where the root is node . Now you want to prune this tree. Each time, you may choose a node that has not been pruned yet, and then prune all nodes in the subtree of (including itself). The process stops if and only if you prune node .
You know that the path from to is the “stem” of this tree and needs special handling. Therefore, at the -th pruning, you must perform the operation on (rather than just pruning it indirectly). In other words, you are not allowed, at the -th pruning or any earlier pruning, to perform the operation on any ancestor of so that 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 such that the chosen at the -th step is different. Output the answer modulo .
Input Format
The first line contains three integers . The next lines each contain two integers , representing an edge in the tree.
Output Format
Output one integer, the answer modulo .
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 , there is only one valid sequence of operations: the first operation chooses , the second chooses , and the third chooses .
For sample , 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.
| Special Property | |||
|---|---|---|---|
| None | |||
| None | |||
| None |
Special property : guaranteed that .
Special property : guaranteed that .
Special property : guaranteed that has an edge with .
For of the testdata, .
Translated by ChatGPT 5