#K9266. Maze Path Existence with Row Swap Operations
Maze Path Existence with Row Swap Operations
Maze Path Existence with Row Swap Operations
You are given a maze represented by an n × m grid. Each cell in the grid is either empty (denoted by .
) or blocked (denoted by #
). In addition, you are provided with q operations. Each operation is a pair of integers \((x, y)\) which indicates that you should swap row \(x\) with row \(y\) of the maze (the rows are 1-indexed).
After performing all the operations in the given order, determine whether there exists a path from the top-left cell \((1,1)\) to the bottom-right cell \((n, m)\). In the maze, you can move up, down, left, or right, but you can only travel on empty cells. If the path exists, output "YES"; otherwise, output "NO".
inputFormat
The input consists of several lines:
- The first line contains three space-separated integers \(n\), \(m\), and \(q\), where \(n\) and \(m\) are the dimensions of the grid, and \(q\) is the number of operations.
- The next \(n\) lines each contain a string of length \(m\) made up of the characters
.
and#
representing the maze grid. - The following \(q\) lines each contain two space-separated integers \(x\) and \(y\) indicating that row \(x\) and row \(y\) should be swapped.
All swaps are applied sequentially in the order they appear in the input.
outputFormat
Output a single line containing either "YES" or "NO". Output "YES" if there exists a path from the top-left corner to the bottom-right corner after all operations; otherwise, output "NO".
## sample4 4 2
....
.#..
..#.
....
1 3
3 4
YES