#d1807. 矩阵操作
矩阵操作
Matrix Operation
Problem Source
Problem Description
There is an integer matrix , where each number is in the range .
In one operation, you may perform one of the following two types:
- For any row , change every number in that row to .
- For any column , change every number in that column to .
Given , determine whether can be turned into the all-zero matrix by several such operations. If yes, output the minimum number of operations; otherwise output .
Input Format
One line with three integers , , .
The next lines each contain numbers, representing the initial state of matrix .
Output Format
One line: if possible, output the number of operations; otherwise output .
Sample Input 1
3 3 10
0 0 9
0 0 9
9 9 8
Sample Output 1
2
Sample Input 2
3 3 10
1 0 9
0 0 9
9 9 8
Sample Output 2
-1
Constraints
, , .