P29436 [洛谷] [BalticOI 2017] Friends
提高+
题目描述

Problem Background

High school is about making the best friends!
Headmistress Umbridge is investigating the friendship situation at Hogwarts School!

Problem Description

There are $n$ students in the school, and their friendship situation satisfies the following conditions:

  • If $a$ is friends with $b$, then $b$ is also friends with $a$;
  • Students can be divided into groups, with each student belonging to exactly one group, and:
  • Each group has at least 1 and at most $p$ students;
  • Each group has at most $q$ pairs of friends where one person is in this group and the other is in a different group.

Two students in the same group are not necessarily friends.
Now she asks you to determine if the students are lying.
If they are not lying, she wants you to provide a reasonable grouping pattern.

Input Format

The first line contains three integers $n, p, q$, representing the number of students, the limit on the number of students in a group, and the limit on the number of cross-group friendships, respectively.
Student numbers range from $0$ to $n - 1$.
The next $n$ lines, starting from the 0th student, first contain an integer $m_i$ representing how many friends this student has, followed by $m_i$ integers representing their friends.

Output Format

If the students are lying, output detention and end the program.
If the students are not lying, first output home.
Then output an integer $G$ representing that the students can be divided into $G$ groups.
The next $G$ lines each start with an integer $G'$ representing the number of students in this group, followed by $G'$ integers $g_i$ representing the student numbers in this group.
Any valid grouping pattern is acceptable.

Sample Input and Output

Sample Input #1

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

Sample Output #1

home
2
2 0 1
2 2 3

Sample Input #2

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

Sample Output #2

detention

Sample Input #3

3 3 3
2 1 2
2 0 2
1 0

Sample Output #3

detention

Notes

Data Range and Constraints

This problem uses subtask testing.

  • Subtask 1 (20 pts): $n \le 16$.
  • Subtask 2 (37 pts): $n \le 250$, $q \le 2$.
  • Subtask 3 (12 pts): $q \le 2$.
  • Subtask 4 (31 pts): No special restrictions.

For $100\%$ of the data, $1 \le n \le 2500$, $p + q \le 15$, $\sum m_i \le 30000$, students do not consider themselves friends.

This problem uses a Special Judge.

Explanation

Translated from BOI 2017 D2 T2 Friends.
Translator: @一只书虫仔.

Special Judge Hint Messages:
- Accepted: Correct answer.
- Wrong Answer[0]: Incorrect judgment.
- Wrong Answer[1]: Some group sizes do not meet the requirements.
- Wrong Answer[2]: A group contains a person with an ID not in the range $0$ to $n-1$.
- Wrong Answer[3]: Some people belong to multiple groups.
- Wrong Answer[4]: Some people do not belong to any group.
- Wrong Answer[5]: The grouping does not meet the requirements.

Special Judge Author: @FZzzz.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 2 1 1 1 2 0 2 2 1 3 1 2
样例输出
home 2 2 0 1 2 2 3