PEG Test - December 2014
PEG is hosting its first annual Secret Santa! To preserve secrecy
amongst the Santas, Alex numbers the
PEG students
from
to
. Their names will henceforth correspond to these numbers.
In Secret Santa, everybody's name is placed into a hat. Alex carries the
hat around the classroom, and each person draws a name from the hat that
is guaranteed to not be their own. Each person keeps their selection a
secret, and must send a gift to that person later on.
Ben's job during the name draw was to follow Alex around and write down which person drew which person, in case anybody forgets their selection and later comes to ask. However, amidst all his university application papers, Ben has lost the sheet that recorded each person's selection. PEG members are naturally forgetful. As expected, a few days before the gifting and reveal, many students reported that they've forgotten the name of the person they've drawn. When all these people went to consult Ben, he became visibly distraught. Drastic action must be taken. So, Ben went around and secretly asked everybody to give a list of names of their possible partners.
Each person gives Ben a list of names of people that might be their partner. Clearly, for someone who remembers their partner's name, this list will contain exactly one name. For someone who hasn't a clue who their partner is, this list will contain everybody's name. It is guaranteed that a person's list will contain their partner. Using these hints, Ben would like to determine one valid way to reassign names to those who have forgotten, such that everybody in PEG has a distinct secret Santa.
Input Specification
Line will contain a single integer
, specifying the number of
students.
For the next lines, each line will correspond to a student. More
specifically, line
will describe the list of possible partners
given by student
.
For each of these lines, the first number on the line will describe how
many people are on the list, and then the actual list will follow on
that line. For example, a line containing 4 10 11 12 13
means that the
student's potential selection could've been either one of students ,
,
, and
.
Output Specification
Output a single line containing space-separated integers, describing
the Secret Santa configuration. Student
(for
) is the
secret Santa of the
-th integer on the line. It is guaranteed that a
solution, although not necessarily unique, will exist. You may output
any such solution.
Sample Input
5
1 2
2 3 5
1 1
4 1 2 3 5
1 4
Sample Output
2 3 1 5 4
Explanation
Student knows for sure that his choice is student
. Student
forgot
whether he picked student
or
. Student
knows for sure that he
picked student
. Student
completely forgot, so it could've been
anybody of
,
,
, or
. Student
knows for sure that he picked
student
. In other words, we don't know the choices for students
or
. We DO know that if
picked
, then
must have picked
, or if
picked
, then
must have picked
. So another valid answer is
2 5 1 3 4
.
Comments
Any PyPy3 code submitted to this question errors with "failed initializing", anyone know why?
The memory limit for this problem is 16 MB. Whenever you run PyPy3, it will always run with a higher memory amount, around 50 MB. Therefore, PyPy3 fails to initialize, given the 16 MB memory limit. (something like this)
I see, thanks!
orz weewoo