#K15311. Magic Matrix

    ID: 24329 Type: Default 1000ms 256MiB

Magic Matrix

Magic Matrix

In this problem, you are given one or more matrices. A matrix is called a (magic) matrix if it satisfies the following conditions:

  1. Each row contains (m) distinct elements.
  2. All elements in the matrix are unique, i.e. the entire matrix has exactly (n \times m) distinct numbers.
  3. Each column contains (n) distinct elements.

Your task is to determine whether each given matrix is a magic matrix. For each matrix, output “YES” if it is magic, and “NO” otherwise.

For example, consider the matrix [ \begin{bmatrix} 1 & 2 \ 3 & 4 \end{bmatrix} ] It has 2 distinct numbers in each row, 4 distinct elements overall, and 2 distinct numbers in each column, so it is a magic matrix.

inputFormat

The input is read from standard input. The first line contains an integer (T), the number of test cases. Then, for each test case, the first line contains two integers (n) and (m) — the number of rows and columns of the matrix. This is followed by (n) lines, each containing (m) space-separated integers, representing the rows of the matrix.

outputFormat

For each test case, output a single line containing the string "YES" if the matrix is a magic matrix, or "NO" otherwise. The result for each test case should be printed on a new line.## sample

1
2 2
1 2
3 4
YES