Connect
Time limit1sMemory limit128 MB
Determine whether the last of alternating Twixt pegs placed on a bounded board completes a connected path joining the placing player's two opposing endzones.
- Level
Medium7 of 10
- Topics
- Graph, Union-find, Simulation, Geometry
- Solved
- No attempts yet
Problem
Your task is to decide whether a given sequence of moves in the board game Twixt ends with a winning move.
In this version of the game the board size may vary. Pegs are placed at integer coordinates in the range . Two players, Black and White, each use pegs of their own color. Black always moves first, and the players then alternate, each move placing one peg on an unoccupied position .
Black's endzones are the lines where or ; White's endzones are the lines where or . Neither player may place a peg inside the other player's endzones.
After each move, the peg just placed is connected by a segment to every peg of the same color that is a chess knight's move away (a difference of in one coordinate and in the other), provided the new segment touches no previously added segment except at a shared endpoint. If a new segment would cross or overlap any existing segment (of either color), that segment is simply not added.
Play stops after a winning move: the move by which a player's segments first complete a connected path linking that player's two endzones.
For example, on a board with : after the moves , , and then , Black playing is a poor move, while Black playing instead would win the game. As another example, on a board with , Black wins in 11 moves: , , , , , , , , , , .
Input
The input contains from 1 to 20 datasets, followed by a line containing only two zeros, 0 0.
The first line of each dataset contains the maximum coordinate and the total number of moves , where , , and is odd. The remaining numbers of the dataset are coordinate pairs, given with one or more pairs per line and all numbers separated by spaces.
Because is odd, Black always makes the last move. All data are legal, and no winning move ever occurs before the last move.
Output
For each dataset, print a single line containing yes if the last move is a winning move, and no otherwise.