#P4258. [WC2016] 挑战NPC
[WC2016] 挑战NPC
Description
Little N has recently been studying NP-complete problems. Seeing him so absorbed, Little O gave him such a problem:
There are balls, numbered from to . There are also baskets, numbered from to . Each basket can hold at most balls.
Each ball can only be placed into specific baskets. Specifically, there are constraints. The -th constraint is described by two integers and , meaning that ball can be placed into basket .
Every ball must be placed into some basket. If a basket contains at most ball, we call such a basket half-empty.
Find the maximum possible number of half-empty baskets, and in an optimal arrangement, determine which basket each ball is placed into.
Little N was stunned and lost his train of thought. Little I, watching from the side, chuckled, “Easy problem!” Then, with a few words, he described a polynomial-time algorithm.
Little N was shocked. Three seconds later, he slapped the table: “No way! This problem is clearly NP-complete. Your algorithm must be wrong!”
Little I smiled slightly: “Then I’ll wait for my Turing Award!”
Little O can make problems but not solve them, so he turned to you—please investigate this problem and write a program to solve it.
Input Format
In the input file , the first line contains a single positive integer , indicating there are test cases.
For each test case, the first line contains three positive integers , , , representing the number of balls, the number of baskets, and the number of constraints.
The next lines each contain two integers , , indicating that ball can be placed into basket .
Output Format
The output file is .
For each test case, first output one line containing a single integer, the maximum possible number of half-empty baskets.
Then output one more line containing integers , separated by spaces, describing one optimal arrangement. Here indicates that ball is placed into basket . If there are multiple optimal solutions, any one of them may be printed.
1
4 3 6
1 1
2 1
2 2
3 2
3 3
4 3
2
1 2 3 3
Hint
For all testdata, , . It is guaranteed that , , and there are no duplicate constraints.
It is guaranteed that there exists at least one feasible solution in which every ball is placed into a basket and the number of balls in each basket does not exceed .
Each test point satisfies the following conventions: ::cute-table{tuack} |Test point| |Notes | |:-:|:--------:|:--------:| |1 | || |2 |^ |^ | |3 || | |4 |^ |There exists a solution with half-empty baskets.| |5 |^ |No solution has any half-empty basket.| |6 |^ |^ | |7 |^ |None | |8 |^ |^ | |9 |^ |^ | |10 |^ |^ |
Translated by ChatGPT 5
京公网安备 11011102002149号