#C3498. Taco Grid Obstacles

    ID: 46931 Type: Default 1000ms 256MiB

Taco Grid Obstacles

Taco Grid Obstacles

You are given a grid with n rows and m columns. Your task is to determine whether it is possible to place obstacles on the grid according to the given constraints.

In each test case, you are provided with an integer k, representing the number of obstacles to be placed, and k pairs of integers \( (r, c) \) representing the row and column positions at which the obstacles must be placed. The obstacles must be placed such that no two obstacles share the same row or the same column. Formally, if you denote the set of rows used by the obstacles as \( R \) and the set of columns as \( C \), then the placement is valid if and only if \( |R| = |C| = k \).

Output "YES" if the obstacles can be placed according to these rules; otherwise, output "NO".

Note: The grid dimensions are provided for context; the primary consideration is the conflict in obstacle positions.

inputFormat

The input is given via standard input (stdin) and consists of multiple test cases.

The first line contains an integer t \((1 \le t \le 100)\) denoting the number of test cases. The description of each test case is as follows:

  • The first line of each test case contains three integers \(n\), \(m\), and \(k\) \((1 \le n, m \le 10^9, 0 \le k \le \min(n, m))\) representing the number of rows, columns, and obstacles respectively.
  • The next \(k\) lines each contain two integers \(r\) and \(c\) \((1 \le r \le n, 1 \le c \le m)\), denoting the row and column positions of an obstacle.

outputFormat

For each test case, print a single line containing either "YES" if it is possible to place all obstacles without having any two in the same row or column, or "NO" otherwise.

The answers for different test cases should be printed on separate lines.

## sample
2
3 3 2
1 1
2 2
3 3 3
1 1
2 2
2 3
YES

NO

</p>