#P9592. 「Daily OI Round 1」Tree
「Daily OI Round 1」Tree
Problem Description
Given three positive integers , you need to construct a rooted tree with root node such that:
- The tree has nodes.
- The sum of distances from every node to the root is .
- For every node that is not a leaf, the number of its direct children is at least .
- 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 .
Input Format
This problem contains multiple test cases.
The first line contains a positive integer , the number of test cases.
For each test case, there is one line with three positive integers , with the meaning as described above.
Output Format
For each test case:
- If a solution exists, output
YESon the first line, then output positive integers on the next line. The -th integer means that is the parent of node , and . - If no solution exists, output
NO.
If there are multiple valid answers, you may output any one of them.
In particular, if 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, . That is, you need to construct a tree with nodes, where the sum of distances from all nodes to node is , and every non-leaf node has at least child nodes.
The following is the tree constructed in the sample:

The distances from nodes to the root node are , respectively, and their sum is , which satisfies the condition. Also, the non-leaf nodes and both have at least children. It can be proven that among all valid constructions, this one has the minimum possible maximum depth, which is here.
Constraints
This problem uses bundled testdata.
| Score | Special Properties | ||
|---|---|---|---|
| None | |||
| or | |||
| None |
For all testdata, it is guaranteed that: , , , , .
Translated by ChatGPT 5