#P8545. Good Subset Family Construction

    ID: 21712 Type: Default 1000ms 256MiB

Good Subset Family Construction

Good Subset Family Construction

We are given a positive integer \(n\) (which in the real contest is either \(529\) or \(625\)) representing the number of warriors, and an integer \(m_{ans}\); you need to construct a family of \(m\) (with \(m \ge 2\)) subsets \(B_1, B_2, \dots, B_m\) of \(A = \{1,2,\dots,n\}\) satisfying the following:

  • Each subset \(B_i\) has at least 3 elements, i.e. \(|B_i| \ge 3\).
  • For every triple \(C \subset A\) (i.e. every 3-element subset of \(A\)), there exists exactly one index \(i\) such that \(C \subset B_i\). In other words, the family \(\{B_i\}_{i=1}^m\) covers each triple exactly once.

Moreover, you must have \(m \le m_{ans}\). Under these conditions, you are asked to output a valid configuration whose \(m\) is as small as possible.


Story Background: In a mysterious realm, Reimu faces a horde of clay warriors (numbered from 1 to \(n\)). These warriors coordinate with each other in several teams (the subsets \(B_i\)) such that every possible trio of warriors fights together in exactly one team. However, due to limitations, the number of teams maintained cannot exceed a given upper bound \(m_{ans}\). Help Reimu by providing one possible arrangement of the teams.

The mathematical requirement can be summarized by the following condition: For every triple \(C \subset A\), there exists exactly one \(i\) such that \(C \subset B_i\). Note that if you decide to take each block to be exactly a triple (i.e. set \(B_i\) is a 3-element subset) then the condition is automatically satisfied. (Since every triple appears only once, by definition.)

Important: Although for the original input \(n\) would be either 529 or 625, for the purpose of this problem you may assume that the given \(n\) is small enough that listing all triples is computationally feasible. In our construction, if the total number of triples, \(\binom{n}{3}\), does not exceed \(m_{ans}\), you can output all 3-element subsets of \(A\) (which is a valid configuration). Otherwise, if \(\binom{n}{3} > m_{ans}\) then you should output -1 to indicate that no valid configuration (with the minimal number \(m\)) exists under the constraint.

inputFormat

The input consists of a single line containing two space‐separated integers:

  • \(n\) --- the total number of warriors.
  • \(m_{ans}\) --- the maximum allowed number of subsets in the answer.

It is guaranteed that \(n\) will be such that a valid configuration exists if \(\binom{n}{3} \le m_{ans}\). You may assume that \(n \ge 4\) (since each subset must have at least 3 elements and at least 2 subsets are required).

outputFormat

If a valid configuration exists then output it in the following format:

  1. On the first line, output the positive integer \(m\), the number of subsets used.
  2. Then output \(m\) lines. The \(i\)th of these lines describes subset \(B_i\) in the following format:
    k a1 a2 \dots ak where \(k = |B_i|\) (note that \(k \ge 3\)) and \(a_1, a_2, \dots, a_k\) are the warriors in that subset (listed in increasing order).

If no valid configuration exists under the constraint \(m \le m_{ans}\), output a single line with -1.

Note: In our solution we construct a valid configuration by taking every 3-element subset of \(A\) if \(\binom{n}{3} \le m_{ans}\). This guarantees that each triple appears exactly once.

sample

7 35
35

3 1 2 3 3 1 2 4 3 1 2 5 3 1 2 6 3 1 2 7 3 1 3 4 3 1 3 5 3 1 3 6 3 1 3 7 3 1 4 5 3 1 4 6 3 1 4 7 3 1 5 6 3 1 5 7 3 1 6 7 3 2 3 4 3 2 3 5 3 2 3 6 3 2 3 7 3 2 4 5 3 2 4 6 3 2 4 7 3 2 5 6 3 2 5 7 3 2 6 7 3 3 4 5 3 3 4 6 3 3 4 7 3 3 5 6 3 3 5 7 3 3 6 7 3 4 5 6 3 4 5 7 3 4 6 7 3 5 6 7

</p>