#K94432. Student Class Allocation
Student Class Allocation
Student Class Allocation
In this problem, you are given students and classes, where each class can accommodate at most students. Each student provides a list of class preferences in order of priority. Your task is to allocate each student to a class according to their preferences. The allocation process is performed in order: for each student, assign them to the first class in their preference list that still has available capacity. If a student cannot be assigned to any of their preferred classes, then the allocation is considered impossible.
Mathematically, if we denote the capacity of each class by , the number of students by , and the number of classes by , then an allocation is valid if for every student , there exists a class in their preference list such that the total number of students allocated to class is at most .
If an allocation is possible, output "Possible" followed by the assignment of each student (using 1-indexed class numbers). Otherwise, output "Impossible".
inputFormat
The input is given via standard input (stdin).
The first line contains three space-separated integers: , , and , representing the number of students, the number of classes, and the maximum capacity of each class respectively.
This is followed by lines. The th line contains a sequence of integers where the first integer is the number of preferences for the th student, followed by distinct integers representing the student's class preferences (each integer is between 1 and ).
outputFormat
Output the result to standard output (stdout).
If it is possible to allocate all students according to their preferences, print "Possible" on the first line, followed by lines each containing the allocated class (1-indexed) for the corresponding student.
If it is not possible, output "Impossible".## sample
6 3 2
3 1 2 3
2 2 3
3 1 3 2
1 3
3 2 1 3
2 3 1
Possible
1
2
1
3
2
1
</p>