#P6862. [RC-03] 随机树生成器
[RC-03] 随机树生成器
Description
Little R has a random tree generator. It works as follows:
- Input . Then for each , randomly choose a node in as its parent. Output the resulting tree.
Given , Little R wants to know, among all possible trees with nodes that can be generated, the sum of the degrees of node .
Since the answer may be very large, output the answer modulo .
Input Format
This problem has multiple test cases.
The first line contains an integer, the number of test cases .
The next lines each contain two positive integers .
Output Format
Output lines. Each line contains one integer: the answer for that test case modulo .
3
3 1
3 2
3 3
3
3
2
Hint
[Sample Explanation]
- Testdata : There are two cases, where the degree of node is and . Therefore the answer is .
- Testdata : There are two cases, where the degree of node is and . Therefore the answer is .
- Testdata : There are two cases, where the degree of node is always . Therefore the answer is .
[Constraints]
This problem uses bundled testdata.
For of the testdata, , . The detailed constraints are as follows.
- Subtask 1 (20 points): , .
- Subtask 2 (55 points): , .
- Subtask 3 (20 points): .
- Subtask 4 (5 points): No additional constraints.
Translated by ChatGPT 5
京公网安备 11011102002149号