P2361 yyy Chess
Description
uim has been studying a game called “yyy Chess.”
The rules are simple: there is an $A \times B$ board and black/white pieces. Two players take turns placing a piece on a cell. You may play either black or white and may switch colors during the game. You may place a piece anywhere you like, as long as the following conditions are satisfied:
1. The cell is not already occupied by another piece.
2. In the four orthogonal neighboring cells (up, down, left, right) of the target cell, there must not be a piece of the same color as the one you are about to place.
3. The first player must place a black piece.
Whoever has no legal move loses.
uim drags you in, hoping you will play with him.
Since you are busy and reluctant, uim makes a concession and allows you to choose to play first or second.
You suddenly recall an elementary math puzzle: two people sit on opposite sides of a table and alternately place coins on the table; coins cannot overlap; whoever cannot place a coin loses. This feels similar, so you plan to borrow that idea.
You know that, with a certain strategy, you are guaranteed to win with $100\%$ certainty.
Since that is the case, let uim lose quickly.
Input Format
The first line contains $A, B$, two integers representing the board size.
The following lines describe uim’s moves in order. Each line contains three integers $x_i, y_i, c_i$, representing the position and the color. Color $1$ is black, and color $0$ is white. Positions satisfy $1 \le x_i \le A$, $1 \le y_i \le B$.
If uim finds no legal move, he might cheat by placing a piece in an illegal position. In that case, you should also point it out. Of course, uim might also stop moving once he knows he has lost. It will not happen that uim resigns while the outcome of the game is still undecided.
Output Format
On the first line, choose whether to play first or second. Output `First` for first, or `Second` for second.
On the following lines, if you are the first to move, output your first move. Then respond to each of uim’s moves. Output $x_i\ y_i\ c_i$, with the same meaning as above.
You must output a forced-winning strategy; otherwise you will get `WA` on this test.
If multiple strategies are winning, output one that finishes the game as early as possible.
Before you place your move, pretend you do not know uim’s next move.
If uim cheats, output `Buwanle` on that line and terminate the program, ignoring any remaining input.
Explanation/Hint
For $40\%$ testdata, $2 \le A, B \le 3$.
For $100\%$ testdata, $2 \le A, B \le 9$.
As the first problem in the monthly contest, it is naturally simple. The core of the reference solution has only 6 lines of code. No complex algorithms are needed to obtain the answer.
Translated by ChatGPT 5