P16221 [ECUSTPC 2025] Purification Operation

Description

Maddy will control a king to wipe out Baddy’s evil chariot (rook) legion. Specifically, they are now playing a game on an infinite chessboard. Baddy controls $n$ black rooks. These rooks stay fixed at their initial positions and do not move during the game. They are placed on the squares $(x_1, y_1), (x_2, y_2), \dots, (x_n, y_n)$. Maddy chooses a position $(X, Y)$ to place her white king. The king can move to any of the 8 adjacent squares. For example, if the king is on $(p, q)$, then it can move to $(p-1, q-1), (p-1, q), (p-1, q+1), (p, q-1), (p, q+1), (p+1, q-1), (p+1, q), (p+1, q+1)$. A black rook attacks a white piece if they are in the same row or the same column, and there is no other piece between them blocking the line of sight. The rook’s own square is not considered part of its attack range. Maddy’s goal is to control the white king to capture all of Baddy’s black rooks. More precisely: - The white king may move freely according to the rules above, but during movement it must not enter any black rook’s attack range; otherwise, the king will be captured by a rook. - If the king moves onto a square occupied by a black rook, that rook is captured and will no longer be able to attack the king afterward. Maddy wants to capture all $n$ rooks. Determine whether there exists an order of captures and a movement path for the king such that it can eventually capture all rooks.

Input Format

The first line contains an integer $T$ ($1 \le T \le 10^5$), the number of test cases. For each test case, the first line contains an integer $n$ ($1 \le n \le 10^5$), the number of black rooks. The next line contains two integers $X$ and $Y$ ($1 \le X, Y \le 10^9$), the initial position of Maddy’s white king. Then follow $n$ lines, each containing two integers $x_i$ and $y_i$ ($1 \le x_i, y_i \le 10^9$), the coordinates of the $i$-th black rook placed by Baddy. It is guaranteed that $\sum n \le 3 \times 10^5$ over all test cases, and within each test case, all rook positions $(x_i, y_i)$ are pairwise distinct. Also, at the start of the game, the white king is not in the attack range of any black rook.

Output Format

For each test case, if the white king can eventually capture all black rooks, output one line containing the string YES; otherwise, output one line containing the string NO. Note that the judge is case-insensitive for YES and NO. In other words, if the answer is affirmative, outputs like yes, YES, Yes, YeS, etc. will all be accepted.

Explanation/Hint

### Sample 1 Explanation For the 1st sample case, the king can capture the black rook in one move. For the 3rd sample case, the diagram of the board is as follows. The first dimension increases from left to right, and the second dimension increases from bottom to top. The bottom-left square is (1, 1): One feasible plan is shown in the figure, where the blue numbers indicate the king’s position at the corresponding step. :::align{center} ![](https://cdn.luogu.com.cn/upload/image_hosting/u0otsm68.png) ::: Translated by ChatGPT 5