#P17194. [KOI 2026 #2] 分发零食
[KOI 2026 #2] 分发零食
Problem Description
There are students and snacks. Both students and snacks are numbered , respectively.
Each student likes at least one of these snacks. More specifically, student () likes snacks, whose indices are .
At the beginning, there is exactly one copy of each of the types of snacks in the room. Now we distribute the snacks to the students using the following process:
- Choose a suitable order, and each time let one student enter the room.
- A student who enters the room will take away all remaining snacks in the room that they like. If there are no snacks left in the room that they like, they take nothing.
Please choose a suitable order for the students to enter the room, and determine whether it is possible to make every student take exactly one snack. If it is possible, output any order that satisfies the requirement.
Input Format
The first line contains an integer , which represents the number of students and the number of snacks.
The next lines describe the snacks liked by the students. On line (), it gives the space-separated integer followed by integers .
Output Format
If there is no order that allows all students to take exactly one snack, output -1 on the first line.
If, when students enter the room in the order of indices , every student can take exactly one snack, then output space-separated integers on the first line.
If there are multiple feasible outputs, any one of them will be accepted.
3
2 1 2
2 2 3
1 2
3 1 2
2
2 1 2
2 1 2
-1
4
1 3
1 2
3 4 2 3
2 1 2
1 2 3 4
Hint
Explanation of Sample 1
The snacks liked by each student are as follows:
- Student likes snack and snack .
- Student likes snack and snack .
- Student likes snack .
If students , , and enter the room in this order, then each student will take exactly one snack.
- At the beginning, there is one copy each of snack , snack , and snack in the room.
- After student enters, they take snack . After that, snacks and remain in the room.
- After student enters, they take snack . After that, only snack remains in the room.
- After student enters, they take snack .
Similarly, even if students , , and enter the room in this order, all students will still take exactly one snack.
Explanation of Sample 2
Both students like all types of snacks, so no matter in what order they enter the room, the first student to enter will take all snacks.
Constraints
- All given values are integers.
- For each integer (),
- For each integer () and integer (),
- For each integer (), the integers are pairwise distinct.
Subtasks
- ( points) For each integer (), .
- ( points) If there exists an order that allows all students to take exactly one snack, then the order also satisfies the requirement.
- ( points) .
- ( points) .
- ( points) .
- ( points) .
- ( points) No additional constraints.
Translated by ChatGPT 5