#P9592. 「Daily OI Round 1」Tree

「Daily OI Round 1」Tree

Problem Description

Given three positive integers n,d,kn, d, k, you need to construct a rooted tree with root node 11 such that:

  • The tree has nn nodes.
  • The sum of distances from every node to the root is dd.
  • For every node that is not a leaf, the number of its direct children is at least kk.
  • Among all valid trees, the maximum depth of all nodes is as small as possible.

Notes:

  • Distance: the number of edges on the simple path between two nodes.
  • Leaf node: a non-root node that has no children.
  • The depth of the root is 00.

Input Format

This problem contains multiple test cases.

The first line contains a positive integer TT, the number of test cases.
For each test case, there is one line with three positive integers n,d,kn, d, k, with the meaning as described above.

Output Format

For each test case:

  • If a solution exists, output YES on the first line, then output n1n-1 positive integers on the next line. The ii-th integer aia_i means that aia_i is the parent of node i+1i+1, and aiia_i \le i.
  • If no solution exists, output NO.

If there are multiple valid answers, you may output any one of them.

In particular, if n=1n=1 and a solution exists, output an empty line for the construction.

3
5 4 1
5 6 1
5 7 1
YES
1 1 1 1
YES
1 1 3 3
YES
1 2 2 2
3
5 4 2
5 6 2
5 7 2
YES
1 1 1 1
YES
1 1 3 3
NO

Hint

Sample Explanation

For the second query of the second sample, n=5,d=6,k=2n=5, d=6, k=2. That is, you need to construct a tree with 55 nodes, where the sum of distances from all nodes to node 11 is 66, and every non-leaf node has at least kk child nodes.

The following is the tree constructed in the sample:

The distances from nodes 1,2,3,4,51,2,3,4,5 to the root node 11 are 0,1,1,2,20,1,1,2,2, respectively, and their sum is 66, which satisfies the condition. Also, the non-leaf nodes 11 and 33 both have at least 22 children. It can be proven that among all valid constructions, this one has the minimum possible maximum depth, which is 22 here.

Constraints

This problem uses bundled testdata.

Subtask\text{Subtask} Score nn \le Special Properties
00 55 1010 None
11 2020
22 10510^5 k=n1k= n-1
33 k=n1k= n-1 or n2n-2
44 1010 T=1T=1
55 7070 None

For all testdata, it is guaranteed that: 1n1051 \le n \le 10^5, 1T1051 \le T \le 10^5, 1k1051 \le k \le 10^5, n106\sum n \le 10^6, 1d10101 \le d \le 10^{10}.

Translated by ChatGPT 5