NONNEG
Let be an square matrix. The elements of the matrix are either integer numbers (positive or negative) or the special value (infinity). We know that in each row of the matrix, there are at most elements that contain numbers - for brevity, we will call them "numeric elements."
We play the following game: In each move, we first choose a number (where ) and an integer number , and then:
- we add to all numeric elements in the -th row of , and
- we subtract from all numeric elements in the -th column of .
We win the game if we find a sequence of moves that, when executed sequentially, result in all numeric elements of the matrix containing non-negative values.
Input Data
The first line of the input will contain two natural numbers and , separated by a single space. The first one will indicate the number of matrices to follow, and the second one the dimension of the matrices. The next lines of the input will give consecutively the elements of matrices as follows: lines from to will correspond to matrix , lines from to will correspond to matrix , etc. The input line corresponding to the -th row of matrix will first contain a number , representing the number of numeric elements in the row (). Then, it will contain pairs of numbers , , each one indicating that the element of the matrix contains the value . It will hold that and . Numbers in each line will be separated in pairs by a single space.
Output Data
The output should consist of lines, each containing one of the words "true" or "false". The -th line of the output should contain "true" if and only if there exists a sequence of moves that wins the game for matrix .
Constraints
Execution time limit: 1 sec.
Memory limit: 64 MB.
Example of Input - Output
STDIN (nonneg.in)
2 4
2 1 8 3 -2
2 2 2 3 5
2 2 0 4 4
2 1 -1 3 7
2 2 -1 4 -1
0
2 2 9 4 -2
1 1 0
STDOUT (nonneg.out)
true
false
Explanation of the Example: The example contains the two matrices, and , given above. For , we can win the game, for example, with the sequence of moves [, ]. On the contrary, for , it is not possible to win the game with any sequence of moves. (Try it!)
Comments