P16403 [ECUSTPC 2026 Spring] Purification Operation 2
Description
Maddy is still wiping out Baddy’s evil army.
The game is played on an infinite Chinese chess board. The board consists of countless horizontal and vertical lines. Each intersection can hold one piece. For convenience, we model it as a 2D Cartesian coordinate system, and use 2D Cartesian coordinates to represent the positions of pieces.
Baddy controls $n$ black pawn pieces and one black general piece. These pieces stay fixed at their initial positions throughout the game and will not move. The black pawns are placed at intersections $(x_1, y_1), (x_2, y_2), \dots, (x_n, y_n)$, and the black general is at $(x_K, y_K)$.
Now Maddy controls one red cannon piece. She can place the red cannon at any empty position (intersection) on the board. The red cannon follows the movement rules of Chinese chess, specifically:
- Move: move any number of squares along its current horizontal line or vertical line. In one move it can only choose horizontal or vertical, not both. It cannot cross over other pieces on the same line, and it also cannot capture during a move.
- Capture: choose an enemy piece on the same line (horizontal or vertical) as the target, but there must be exactly one piece in between (any piece). After capturing, the cannon moves to the position of the captured enemy piece, and the captured piece is removed from the board.
After placing the red cannon, Maddy may keep moving it any number of times according to the rules above.
Maddy now wants to know whether there exists a valid placement plan and a sequence of moves for the red cannon that can eventually capture the black general. Please help her.
Input Format
The first line contains an integer $T\ (1 \le T \le 10^5)$, the number of testdata.
For each testdata, the first line contains $3$ integers $n, x_K$ and $y_K\ (0 \le n \le 10^5, -10^9 \le x_K, y_K \le 10^9)$, representing the number of black pawns and the coordinates of the black general.
Then follow $n$ lines. The $i$-th line contains two integers $x_i, y_i (-10^9 \le x_i, y_i \le 10^9)$, representing the position of the $i$-th black pawn.
It is guaranteed that $\sum n \le 3 \times 10^5$ over all testdata. It is guaranteed that within each testdata, all black pawns have pairwise distinct positions, and the black general’s position is different from every black pawn’s position.
Output Format
For each testdata, if there exists a valid placement plan and a sequence of moves for the red cannon that can capture the black general, output one line with the string YES; otherwise output one line with the string NO.
Note that the judge is case-insensitive for YES and NO. In other words, when the answer is positive, outputs like yes, YES, Yes, YeS, etc. are all accepted.
Explanation/Hint
### Explanation for Sample 1
The figure below shows the positions of Black’s pieces in the $2$-nd testdata and one possible placement position for Maddy’s red cannon, namely at $(-2, -1)$. Then it can capture the black general directly.
:::align{center}

Figure 1: The $2$-nd testdata
:::
The figure below shows the positions of Black’s pieces in the $3$-rd testdata.
:::align{center}

Figure 2: The $3$-rd testdata
:::
Please note that for convenience of demonstration, the sample figures draw the board boundary, but in fact the statement has already pointed out that the board is infinite.
Translated by ChatGPT 5