P14098 [POCamp 2022] Wolves Catch Rabbits II / Djur

Description

In a grid of size $R \times C$, a wolf stands on cell $(1, 1)$ and a rabbit stands on cell $(R, C)$. The wolf wants to walk to cell $(R, C)$, and the rabbit wants to walk to cell $(1, 1)$. There is just one problem: if the two paths intersect each other, the wolf will chase the rabbit along the rabbit's path. Now we want to know: given the appearance of the grid, can we find a pair of non-intersecting paths, one for the rabbit and one for the wolf? The start and end cells ($(1, 1)$ and $(R, C)$) are not counted as part of the paths.

Input Format

The first line contains two integers: $R, C$. In all tests, $2 \le R \cdot C \le 2 \cdot 10^5$. The next part is an $R \times C$ grid. Each cell is either `.`, denoting an empty cell, or `#`, denoting an obstacle. It is guaranteed that cells $(1, 1)$ and $(R, C)$ are empty.

Output Format

If no two paths satisfying the requirements exist, output `NO`. Otherwise, output one line `YES`. Then output a grid in which the rabbit's path is marked with `K` and the wolf's path is marked with `V`. Note that in the output all obstacles must remain obstacles, and all empty cells that are not on a path must remain empty cells. Each path must be connected. If you use `C++`, to avoid `Time Limit Exceeded` on a correct solution, it is recommended to use `\n` instead of `endl`.

Explanation/Hint

### Subtasks **This problem uses bundled test cases.** | Subtask | Points | Restrictions | |:-:|:-:|---| | 1 | 9 | no obstacles | | 2 | 10 | $R \cdot C \le 10$ | | 3 | 20 | $R = 3$ | | 4 | 25 | $R \cdot C \le 1000$, and it is guaranteed that a solution exists in which the wolf only moves down and right, and the rabbit only moves up and left | | 5 | 36 | no additional restrictions | Translated by QwenWork