#P1971. [NOI2011] 兔兔与蛋蛋游戏

    ID: 917 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2011NOI 系列深度优先搜索,DFS二分图

[NOI2011] 兔兔与蛋蛋游戏

Description

These days, Tutu and Dandan have taken a liking to a new board game.

The game is played on an nn-by-mm board. Before the game starts, exactly one cell on the board is empty, and every other cell contains a piece that is either black or white.

In each game, Tutu always moves first, and then the two players alternate. The moves are defined as follows:

  • On Tutu’s turn, she chooses a white piece adjacent to the empty cell and moves it into the empty cell.
  • On Dandan’s turn, he chooses a black piece adjacent to the empty cell and moves it into the empty cell.

The first player who cannot move according to the rules loses the game. For convenience, the operation “move the piece in row xx, column yy into the empty cell” is denoted by M(x,y)M(x,y).

For example, here are three sample games.

Recently Tutu keeps losing, and Dandan is especially smug about it, so Tutu asks her good friend—you—for help. She brings you the full move log of a game she lost to Dandan. Please point out every move where she “made a mistake” in that game.

Note:

  • Two cells are adjacent if and only if they share a common side.
  • Tutu’s move is a “mistake” if and only if, before the move Tutu had a winning strategy, and after the move Dandan has a winning strategy.

Input Format

The first line contains two positive integers n,mn, m.

The next nn lines describe the initial board. The ii-th of these lines contains mm characters. Each character is one of the uppercase letters X, O, or the dot .. They denote a black piece, a white piece, and an empty cell, respectively. The dot . appears exactly once.

The next line contains an integer kk (1k10001 \leq k \leq 1000), indicating that Tutu and Dandan each made kk moves.

The next 2k2k lines describe the game. The (2i1)(2i - 1)-th line is Tutu’s ii-th move (the move with index ii), and the 2i2i-th line is Dandan’s ii-th move. Each move is described by two integers x,yx, y, meaning the piece at row xx, column yy is moved into the empty cell.

The input guarantees that there is exactly one empty cell on the board; every move made by Tutu and Dandan is legal; and Dandan wins in the end.

Output Format

The first line contains an integer rr, the total number of mistakes made by Tutu.

Then output rr lines in increasing order, giving the indices of Tutu’s “mistaken” moves. The ii-th of these lines contains an integer aia_i, meaning that Tutu’s ii-th mistake is her aia_i-th move in the game.

1 6 
XO.OXO 
1 
1 2 
1 1 
1
1
3 3 
XOX 
O.O 
XOX 
4 
2 3 
1 3 
1 2 
1 1 
2 1 
3 1 
3 2 
3 3 
0
4 4 
OOXX 
OXXO 
OO.O 
XXXO 
2 
3 2 
2 2 
1 2 
1 3 
2
1
2

Hint

For 100%100\% of the testdata, 1n401 \leq n \leq 40, 1m401 \leq m \leq 40, 1k10001 \leq k \leq 1000.

::cute-table{tuack}

Test point ID nn mm
1,21,2 n=1n=1 1m201\leq m\leq 20
33 n=3n=3 m=4m=4
4,54,5 n=4n=4
6,76,7 m=5m=5
88 n=3n=3 m=7m=7
9149\sim 14 n=2n=2 1m401\leq m\leq 40
15,1615,16 1n161\leq n\leq 16 1m161\leq m\leq 16
172017\sim 20 1n401\leq n\leq 40 1m401\leq m\leq 40

Translated by ChatGPT 5