#C11964. Chessboard Safe Position Problem

    ID: 41338 Type: Default 1000ms 256MiB

Chessboard Safe Position Problem

Chessboard Safe Position Problem

You are given an \( n \times n \) chessboard and \( m \) queens placed on the board. A queen can attack any position in the same row, same column, or on a diagonal. More formally, a queen at position \( (q_x, q_y) \) can attack a cell \( (x, y) \) if any of the following conditions hold:

[ x = q_x \quad\text{or}\quad y = q_y \quad\text{or}\quad |x - q_x| = |y - q_y| ]

Your task is to determine if there exists at least one safe position on the chessboard where a knight (or any piece) could be placed such that it is not under attack by any queen. If such a position exists, print "Yes"; otherwise, print "No".

Note: The queens do not block each other’s attack paths.

inputFormat

The input is read from standard input (stdin) and has the following format:

T
n m
x1 y1
x2 y2
... (m lines for the m queens)
... (repeat the above for T test cases)

Where:

  • T is the number of test cases.
  • For each test case, the first line contains two integers: \( n \) (size of the chessboard) and \( m \) (the number of queens).
  • The next \( m \) lines each contain two integers \( x \) and \( y \), representing the 0-indexed coordinates of a queen on the chessboard.

outputFormat

For each test case, output a single line to standard output (stdout) containing either "Yes" if there exists at least one safe position on the chessboard, or "No" if every position is under attack by at least one queen.

## sample
3
8 2
0 0
7 7
4 4
0 0
1 1
2 2
3 3
4 2
0 0
0 1
Yes

No Yes

</p>