#P6575. [BalticOI 2017] Friends
[BalticOI 2017] Friends
Description
There are students in the school, and their friendships satisfy the following conditions:
- If and are friends, then and are also friends.
- The students can be divided into groups. Each student belongs to exactly one group, and:
- Each group has at least student and at most students.
- In each group, there are at most pairs of friends such that one student is in this group and the other student is in a different group.
Two students in the same group do not necessarily have to be friends.
Now she asks you to determine whether these students are lying.
If they are not lying, she wants you to provide a valid grouping.
Input Format
The first line contains three integers , representing the number of students, the size limit within a group, and the limit on friend pairs across different groups.
Students are numbered from to .
Then follow lines. Starting from student , each line begins with an integer , which is the number of friends of this student, followed by integers indicating who those friends are.
Output Format
If these students are lying, output detention and terminate.
If these students are not lying, first output home.
Then output an integer , meaning the students can be divided into groups.
Next, output lines. Each line starts with an integer , the number of students in this group, followed by integers , the IDs of the students in this group.
Any valid output is accepted.
4 2 1
1 1
2 0 2
2 1 3
1 2
home
2
2 0 1
2 2 3
5 2 1
1 1
2 0 2
2 1 3
2 2 4
1 3
detention
3 3 3
2 1 2
2 0 2
1 0
detention
Hint
Constraints
This problem uses bundled tests.
- Subtask 1 (20 pts): .
- Subtask 2 (37 pts): , .
- Subtask 3 (12 pts): .
- Subtask 4 (31 pts): no special constraints.
For of the testdata, , , , and students are not friends with themselves.
This problem uses Special Judge.
Notes
Translated from BOI 2017 D2 T2 Friends.
Translator: @一只书虫仔.
spj message explanation:
Accepted: the answer is correct.Wrong Answer[0]: wrong judgment.Wrong Answer[1]: the sizes of some groups do not meet the requirements.Wrong Answer[2]: some groups contain IDs not in to .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.
spj author:
Translated by ChatGPT 5
京公网安备 11011102002149号