## Baltic OI '17 P4 - Friends

View as PDF

Points: 35 (partial)
Time limit: 1.0s
Memory limit: 1G

Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
##### Baltic Olympiad in Informatics: 2017 Day 2, Problem 1

High school is all about being in the coolest group of friends. Headmistress Umbridge knows this, and she also knows that knowledge is power. She has collected data on all of the students at the school, asking each of them who they are friends with. Now she has a list of responses, but she is suspicious that some of the students might not have been entirely truthful during the questioning.

From anonymous (but highly reliable) sources, Headmistress Umbridge knows that the friendships at her school satisfy the following properties:

• If is friends with then is also friends with .
• The set of students can be partitioned into groups, such that every student participates in exactly one group, where
• each group has at least one and at most students, and
• for each group there are at most pairs of friends with the first one in the group, and the second one outside of it.

Note that two students in the same group do not have to be friends.

Umbridge has hired you to figure out whether it is possible that all students are telling the truth, or whether she can be sure that at least one student is lying, and that she therefore should put everyone in detention. Is this morally questionable? Probably.

(In case the students may be telling the truth, you are worried that her suspicion might fall on you instead; thus you will also want to provide evidence of a valid partition if there is one.)

#### Input Specificaion

First a single line with three non-negative integers , and as described above. Next follow lines, one for each student, starting with student . Each such line starts with an integer , denoting the number of friends student number claims that she has. Then follow distinct integers between and , indicating who those friends are (the students are numbered from to ).

#### Constraints

We always have , and . Furthermore, it is guaranteed that . A student never lists herself as one of her friends. For subcases, the inputs have these further restrictions:

• Group 1: 20 points
• Group 2: 37 points and
• Group 3: 12 points
• Group 4: 31 points No further restrictions.

#### Output Specification

If Dolores can be certain someone didn't tell the truth, output detention. Otherwise, output home. If you output home on the first line, then you should prove your claim by outputting a partition of the students into groups such that the requirements above hold (if there are several, any one will do): The second line should then contain a positive integer , the number of groups. The following lines should each begin with a positive integer , the number of students in the th group. Then on the same line, integers indicating the students in this group.

#### 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