#Lutece0572. Fill Numbers
Fill Numbers
Migrated from Lutece 572 Fill Numbers
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
Stephydx invented a new puzzle for you to solve! The puzzle is a matrix with rows, and each row consists of grids. Each grid may be empty or have a number in it. But you can assume that there are no more than TWO empty grids at each row and column. Now, we want to fill numbers in each empty grid to make the sum of each row, and each column equal to some specific numbers.
You have to find out whether the solution is unique, or more than one, or we have no solutions at all.
Input
The first line of the input is an integer , indicating the test cases. ()
For each test case, there are two numbers and , indicating the size of the matrix (, ). Then lines follow, each consists of integers, representing rows of the matrix. If the grid is empty, that number will be , otherwise the number will always be non-negative and no more than .
Then a line with integers lists the sum we required for each row, from up to bottom. The next line has integers, listing the sum we required for each column, from left to right.
The absolute value of the required sum of each row and column will not exceed .
Output
For each test case, first print Case #k:
first ,in which represents the case number which starts from , then output a word Unique
, More than one
, or No solution
, as described above.
Samples
5
2 2
1 1
-1 -1
2 4
3 3
2 2
1 1
-1 -1
2 5
3 3
2 2
1 1
2 2
2 4
3 3
4 4
1 2 3 4
1 -1 -1 2
3 -1 -1 4
5 6 7 8
10 6 14 26
10 13 15 18
2 2
1 -1
2 -1
-1 1
3 -3
Case #1: Unique
Case #2: No solution
Case #3: Unique
Case #4: More than one
Case #5: Unique
Note
Please note that although the numbers that are already filled in the matrix are all non-negative, a solution with negative numbers is still acceptable. Also if a row or a column has no empty grids, the sum of that row or column will always equal to the required sum we gave.
Resources
10th UESTC Programming Contest Final