LOCK & KEY

0

0 votes
Problem

The mysterious bank of NITH stores the money of all the students. The students dont trust each other so the bank manager finds a solution. The bank manager puts L locks on the chest in a way that every lock must be unlocked to open the chest. Then he distributes keys to the locks to the students so that every student has some but not all of the keys. Any given lock can have multiple keys, but any given key can only open one lock. Given a number of students and sets of keys assigned to each student, you must find all groups of students that together can open the chest, but do not contain any unnecessary members (i.e., the chest cannot be opened if any student is left out of the group).

Note that there will be too many students for you to simply examine all possible combinations of students, so you will need to be more intelligent in your choice of algorithms.

INPUT: The first line of input will be the number of students N, followed by the total number of locks L. Following will be a line for each student (1..N) listing the number(s) of the locks (1..L) to which the student has keys.

OUTPUT: The output will be all possible combinations of students that can open the chest. Each combination will be on a separate line, with the students listed in order from smallest to largest. The combinations must be listed in order of smallest number of students to largest required. For combinations with the same number of students, list the combinations in lexicographic order (i.e., compare the 1st students, breaking ties by comparing the 2nd students, then the 3rd, etc...).

Sample Input
3 3
1 3
1 2
2 3
Sample Output
1 2 
1 3 
2 3
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

3 students, 3 keys student 1 has keys to lock 1 and 3 student 2 has keys to lock 1 and 2 student 3 has keys to lock 2 and 3

Editor Image

?