#P1285. [NEERC 2001] 队员分组

[NEERC 2001] 队员分组

Description

There are nn people numbered from 11 to nn, with some acquaintance relations among them. Your task is to divide these people into two groups such that:

  • Everyone is assigned to one of the groups.
  • Each group contains at least one person.
  • In each group, every person knows every other member in the same group.

Subject to the above conditions, the absolute difference between the sizes of the two groups should be as small as possible. Please construct one feasible grouping.

Please note that xx knowing yy does not necessarily mean that yy knows xx; xx knowing yy and yy knowing zz does not necessarily mean that xx knows zz. That is, the acquaintance relation is directed and non-transitive.

Input Format

The first line contains an integer representing the total number of people nn.

From line 22 to line (n+1)(n + 1), each line contains several pairwise distinct integers ending with 00. On line (i+1)(i + 1), the jj-th integer ai,ja_{i, j} (excluding 00) indicates that person ii knows ai,ja_{i, j}.

Output Format

This problem uses a Special Judge.

If there is no solution, output a single line containing the string No solution.

If there is a solution, output two lines of integers describing the two groups. On each line, the first integer is the size of that group, followed by the member indices in ascending order, separated by spaces.

5
2 3 5 0
1 4 5 3 0
1 2 5 0
1 2 3 0
4 3 2 1 0

3 1 3 5
2 2 4

5
3 4 5 0
1 3 5 0
2 1 4 5 0
2 3 5 0
1 2 3 4 0

No solution

Hint

Constraints

For all test points, it is guaranteed that 2n1002 \leq n \leq 100, 1ai,jn1 \leq a_{i, j} \leq n.

Explanation

SPJ provided by @zhouyonglong.

Translated by ChatGPT 5