#K9551. Diagonally Dominant Matrix
Diagonally Dominant Matrix
Diagonally Dominant Matrix
Given a square matrix, determine whether it is diagonally dominant. A matrix \(A\) of order \(n\) is said to be diagonally dominant if for every row \(i\) (\(0 \le i < n\)), the following condition holds:
$$ |a_{ii}| \geq \sum_{j \neq i} |a_{ij}|. $$Your task is to process multiple test cases where each test case consists of a matrix. For each matrix, output YES
if it is diagonally dominant and NO
otherwise.
Note: Input will be taken from standard input and the output should be printed to standard output.
inputFormat
The first line of input contains an integer \(T\), the number of test cases. Each test case is described as follows:
- The first line contains an integer \(N\), the order (dimension) of the matrix.
- The following \(N\) lines each contain \(N\) space-separated integers, representing the rows of the matrix.
All input is provided via stdin
.
outputFormat
For each test case, print a single line with YES
if the given matrix is diagonally dominant, or NO
otherwise. The output for all test cases should be written to stdout
, with each result on a new line.
2
3
3 -2 1
1 -4 2
1 2 5
3
1 2 3
2 100 2
3 2 1
YES
NO
</p>