#C535. Taco Maze Path Finding

    ID: 48989 Type: Default 1000ms 256MiB

Taco Maze Path Finding

Taco Maze Path Finding

This problem requires you to determine if there exists a valid path in a maze represented as a 2D grid from the top-left corner to the bottom-right corner. The grid consists of open cells ('.') and blocked cells ('#'). Movement is only allowed in four directions: up, down, left, and right.

If either the start or the goal cell is blocked, the answer is immediately NO. Otherwise, output YES if a path exists, or NO if it does not.

Note: In your solution, use standard Breadth-First Search (BFS) to explore the grid.

The coordinates are based on 0-indexing when processing the grid.

inputFormat

The input consists of multiple lines. The first line contains two space-separated integers N and M, representing the number of rows and columns respectively.

The next N lines each contain a string of length M composed of characters '.' (open cell) and '#' (blocked cell), which form the maze.

N M
row1
row2
...
rowN

outputFormat

Output a single line: YES if there is a valid path from the top-left corner to the bottom-right corner of the maze, and NO otherwise.

## sample
5 5
.....
.###.
.#..#
.#..#
.....
YES

</p>