题目描述
So many students are interested in participating in this year's regional programming contest that we have decided to arrange a screening test to identify the most promising candidates. This test may include as many as 100 problems drawn from as many as 20 categories. I have been assigned the job of setting problems for this test.
At first the job seemed to be very easy, since I was told that I would be given a pool of about 1,000 problems divided into appropriate categories. After getting the problems, however, I discovered that the original authors often wrote down multiple category-names in the category fields. Since no problem can used in more than one category and the number of problems needed for each category is fixed, assigning problems for the test is not so easy.
输入
The input file may contain multiple test cases, each of which begins with a line containing two integers,nk and
np,
where nk is the number of categories and is the number of problems in the pool. There will be between 2 and 20 categories and at most 1,000 problems in the pool.
The second line contains nk positive integers, where the ith integer specifies the number of problems to be included in category i ( 1<=i<=nk) of the test. You may assume that the sum of these nk integers will never exceed 100. The jth ( 1<=j<=np) of the next np lines contains the category information of the jth problem in the pool. Each such problem category specification starts with a positive integer specifying the number of categories in which this problem can be included, followed by the actual category numbers.
A test case containing two zeros for nk and np terminates the input.
输出
For each test case, print a line reporting whether problems can be successfully selected from the pool under the given restrictions, with 1 for success and 0 for failure.
In case of successful selection, print nk additional lines where the ith line contains the problem numbers that can be included in category i. Problem numbers are positive integers not greater then np and each two problem numbers must be separated by a single space. Any successful selection will be accepted.
样例输入
3 15
3 3 4
2 1 2
1 3
1 3
1 3
1 3
3 1 2 3
2 2 3
2 1 3
1 2
1 2
2 1 2
2 1 3
2 1 2
1 1
3 1 2 3
3 15
7 3 4
2 1 2
1 1
1 2
1 2
1 3
3 1 2 3
2 2 3
2 2 3
1 2
1 2
2 2 3
2 2 3
2 1 2
1 1
3 1 2 3
0 0
样例输出
1
8 11 12
1 6 7
2 3 4 5
0
参考代码
暂无
解析
暂无