#P2763. 试题库问题

    ID: 1768 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>网络流Special JudgeO2优化最大流网络流 24 题

试题库问题

Description

Problem description: Assume a question bank contains nn questions. Each question is labeled with one or more types. We need to select mm questions from the bank to form an exam paper, and the paper must include the specified numbers of questions of each type. Design an algorithm that meets this requirement.

Programming task: Given the selection requirements, compute a selection plan that satisfies them.

Input Format

The first line contains two positive integers kk and nn. Here, kk is the total number of types in the question bank, and nn is the total number of questions.

The second line contains kk positive integers; the ii-th integer is the required count of type ii questions. The sum of these kk numbers is the total number of questions to select, mm.

Each of the next nn lines gives the type information for one question. The first positive integer pp indicates that the question belongs to pp types, followed by pp integers that are the type IDs of the question.

Output Format

Output kk lines. On the ii-th line, print i: followed by the indices of the selected questions of type ii. If multiple valid solutions exist, output any one of them. If no solution exists, output No Solution!.

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
1: 1 6 8
2: 7 9 10
3: 2 3 4 5

Hint

2k202 \leq k \leq 20, kn103k \leq n \leq 10^3.

Thanks to @PhoenixEclipse for providing the SPJ.

Translated by ChatGPT 5