#P7589. 黑白棋(2021 CoE-II B)

黑白棋(2021 CoE-II B)

Description

Alice\text{Alice} and Bob\text{Bob} are playing a game called “Reversi”. The rules are as follows.

  • The game is played on the Cartesian coordinate plane.

  • Alice\text{Alice} uses black pieces, and Bob\text{Bob} uses white pieces.

  • Initially, choose any nn lines parallel to the XX axis on the coordinate plane. Their intercepts on the YY axis are all integers and are pairwise distinct. On each line, Alice\text{Alice} places one black piece, and Bob\text{Bob} places one white piece. The XX coordinates of all pieces are integers. The two pieces on the same line are not at the same position.

  • Alice\text{Alice} and Bob\text{Bob} take turns to move, and Alice\text{Alice} always moves first. On each turn, a player first chooses a line, then moves their own-colored piece on that line along the line.

  • A player may move their piece several integer units in one move toward the opponent’s piece; this is called forward. A player may also move their piece several integer units in one move away from the opponent’s piece; this is called backward.
    As long as a forward move does not pass over the opponent’s piece and does not make the black and white pieces overlap, there is no limit on how far the piece can move forward. However, the forward distance must be at least 11. If the above conditions cannot be satisfied, the player cannot make a forward move.
    To avoid the game never ending due to repeated backward moves, in a single game, the total number of backward moves performed by a player cannot exceed kk. Meanwhile, to prevent the game area from becoming too large and inconvenient to display, the distance of each backward move must be at least 11 and at most dd. If the above conditions cannot be satisfied, the player cannot make a backward move.

  • When it is a player’s turn, if they can make a move, they must make exactly one move. This move can be a forward move or a backward move (if the limit on the number of backward moves has not been exceeded).

  • If a player cannot make any move to move their piece, they lose and the game ends.

Given the initial state of the game, assuming that Alice\text{Alice} and Bob\text{Bob} both play optimally, determine whether Alice\text{Alice} can win.

Input Format

The input contains multiple test cases.

The first line contains an integer TT, the number of test cases. Then there is a blank line. Next are TT test cases describing the initial states.

For each test case, the first line contains three integers nn, kk, dd, representing the number of lines, the total allowed number of backward moves, and the maximum distance of each backward move. Then follow nn lines, each containing three integers yiy_i, bib_i, wiw_i, representing the YY intercept of the ii-th line, and the XX coordinates of the black piece and the white piece on that line, respectively (biwib_i \ne w_i).

There is a blank line between every two test cases.

Output Format

If Alice\text{Alice} can win, output Yes; otherwise output No.

2

2 0 10
3 4 8
7 7 5

3 5 15
-3 -9 -19
-7 10 21
12 12 16
Yes
No

Hint

Sample Explanation

The figure below corresponds to the first test case of Input #1. If Alice\text{Alice} uses an optimal strategy, no matter how Bob\text{Bob} moves, Alice\text{Alice} can win.

Below is Alice\text{Alice}’s winning strategy. First, Alice\text{Alice} chooses the line y=3y=3 and moves the black piece from 4 to 6, so that the distance between the black and white pieces on both lines becomes 22. Since kk is 00, backward moves are essentially not allowed. If Bob\text{Bob} chooses to move the white piece on the line y=3y=3, then the two pieces on that line will become adjacent and cannot be moved afterward. Similarly, if Bob\text{Bob} chooses to move the white piece on the line y=7y=7, the two pieces on that line will also become adjacent and cannot be moved afterward. Therefore, no matter what Bob\text{Bob} does, one line will always end up with two adjacent pieces that cannot be moved anymore, while on the other line the distance between the pieces is 22 and can still be moved once. Alice\text{Alice} then moves the remaining movable black piece by one more step. After that, Bob\text{Bob} cannot move any white piece, so Alice\text{Alice} wins.

For the second test case of Input #1, no matter how Alice\text{Alice} moves, Bob\text{Bob} can always win.


Constraints

For 100%100\% of the testdata, 1T1001 \le T \le 100, 1n1001 \le n \le 100, 0k1000 \le k \le 100, 1d201 \le d \le 20, 100yi100-100 \le y_i \le 100, 103bi103-10^3 \le b_i \le 10^3, 103wi103-10^3 \le w_i \le 10^3.

Translated by ChatGPT 5