#P6862. [RC-03] 随机树生成器

[RC-03] 随机树生成器

Description

Little R has a random tree generator. It works as follows:

  • Input nn. Then for each 1<in1<i\le n, randomly choose a node in [1,i)[1,i) as its parent. Output the resulting tree.

Given n,kn,k, Little R wants to know, among all possible trees with nn nodes that can be generated, the sum of the degrees of node kk.

Since the answer may be very large, output the answer modulo 109+910^9+9.

Input Format

This problem has multiple test cases.

The first line contains an integer, the number of test cases TT.

The next TT lines each contain two positive integers n,kn,k.

Output Format

Output TT lines. Each line contains one integer: the answer for that test case modulo 109+910^9+9.

3
3 1
3 2
3 3
3
3
2

Hint

[Sample Explanation]

  • Testdata 11: There are two cases, where the degree of node 11 is 11 and 22. Therefore the answer is 33.
  • Testdata 22: There are two cases, where the degree of node 22 is 11 and 22. Therefore the answer is 33.
  • Testdata 33: There are two cases, where the degree of node 33 is always 11. Therefore the answer is 22.

[Constraints]

This problem uses bundled testdata.

For 100%100\% of the testdata, 1T1051\le T\le 10^5, 1kn1071\le k\le n\le 10^7. The detailed constraints are as follows.

  • Subtask 1 (20 points): T50T\le 50, n8n\le 8.
  • Subtask 2 (55 points): T=1T=1, n105n\le 10^5.
  • Subtask 3 (20 points): T=1T=1.
  • Subtask 4 (5 points): No additional constraints.

Translated by ChatGPT 5