#P9592. Construct a Tree with Given Distance Sum and Branching Constraint

    ID: 22739 Type: Default 1000ms 256MiB

Construct a Tree with Given Distance Sum and Branching Constraint

Construct a Tree with Given Distance Sum and Branching Constraint

You are given three positive integers n, d and k. Your task is to construct a rooted tree satisfying the following conditions:

  • The tree has exactly n nodes with node 1 being the root.
  • The sum of distances from every node to the root is exactly d. (Distance is defined as the number of edges on the simple path between two nodes.)
  • Every non‐leaf node (a node that is not the root and has at least one child, and also the root if it is non‐leaf) has at least k direct children.
  • The maximum depth of the tree (the depth of the deepest node; note that the root is at depth 0) is minimized.

All formulas below are in LaTeX format. In particular, the parameter constraints are:

  • $$ \text{Distance: } d(u, v) = \text{number of edges on the simple path between } u \text{ and } v. $$
  • $$ \text{Leaf node: a non-root node with no children.} $$
  • $$ \text{Root depth: } 0. $$

If there exists more than one valid tree, print any one of them. Otherwise, output -1 if no such tree exists.

inputFormat

The input consists of a single line with three space‐separated integers: n, d, and k.

For example:

6 7 2

outputFormat

If a valid tree exists, output a single line containing n-1 space‐separated integers. The i-th integer (for i from 2 to n) should be the parent of node i in your constructed tree.

If no valid tree exists, output -1.

sample

1 0 1