CF325D Reclamation

题目描述

### 题意简述 给定一个大小为 $r \times c$ 的二维环形网格图,每一行的第 $1$ 格和第 $c$ 格同样相邻。 现在按照给定的顺序将 $n$ 个格子变成障碍物。一个格子可以变成障碍的条件为该格子变成障碍后仍然存在一条从第 $1$ 行到第 $r$ 行的路径。如果一个格子不可以变成障碍,就跳过该操作并且继续处理接下来的格子。路径为四相邻规则。 您需要求出最多可以有多少个格子变成障碍物。

输入格式

输出格式

说明/提示

The pictures below show the sequence of reclamations that are performed in the example input. Blue cells represent the cells occupied by sea, while other colored cells represent land. The latest cell that are reclamated is colored either yellow or red, depending on whether the addition violates the condition in the statement. The dashed red line represents a possible trade route, if it exists. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF325D/d6ec8125e55a1906d7581cbff9a6ee87ddc2353d.png) ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF325D/aef1157a0827de2a801d26fae3b1c851c9f2d8df.png) ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF325D/e133e83ccbd4802abe981cfd4b05c5d7ba860aec.png) ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF325D/1cc7f576d305fdf90a3b9b4943250133612ce65d.png) ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF325D/b3f861e0bbdac64175ce462101d9dcd6abb05302.png) ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF325D/7aacfff1f5d1fec99c575effbe7f4526fc6d63ab.png) No route exists, so this reclamation is not performed. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF325D/0d8309eeef1033c7c6d711bc90d29fb1bf8f05ed.png) ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF325D/9114b7758ba6fee6e395cf86ed73fbca75c14132.png) No route exists, skipped. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF325D/dd3359aa424a23f7486bdb3fd9b4d1736723003a.png) Remember that the leftmost and rightmost cells in the same row are adjacent. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF325D/2b437fd296a68b1926dba0367513cbacf22495c3.png) No route exists, skipped. Hence the result is: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF325D/9d0f47bed88870496229a4384523053b576aaa67.png) There are 6 successful reclamation and 3 failed ones.