|
||||||||||
Prince and PrincessTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 3081 Accepted Submission(s): 909 Problem Description There are n princes and m princesses. Princess can marry any prince. But prince can only marry the princess they DO love. For all princes,give all the princesses that they love. So, there is a maximum number of pairs of prince and princess that can marry. Now for each prince, your task is to output all the princesses he can marry. Of course if a prince wants to marry one of those princesses,the maximum number of marriage pairs of the rest princes and princesses cannot change. Input The first line of the input contains an integer T(T<=25) which means the number of test cases. For each test case, the first line contains two integers n and m (1<=n,m<=500), means the number of prince and princess. Then n lines for each prince contain the list of the princess he loves. Each line starts with a integer ki(0<=ki<=m), and then ki different integers, ranging from 1 to m denoting the princesses. Output For each test case, first output "Case #x:" in a line, where x indicates the case number between 1 and T. Then output n lines. For each prince, first print li, the number of different princess he can marry so that the rest princes and princesses can still get the maximum marriage number. After that print li different integers denoting those princesses,in ascending order. Sample Input
Sample Output
Source | ||||||||||
|