#K45887. Taco's Grid Path

    ID: 27853 Type: Default 1000ms 256MiB

Taco's Grid Path

Taco's Grid Path

You are given an n x m grid where each cell is either traversable ('.') or blocked ('#'). Starting from the top-left corner (cell (1,1)) you need to determine if there exists at least one valid path to reach the bottom-right corner (cell (n, m)). You may move in the four cardinal directions (up, down, left, right) and you cannot pass through blocked cells.

Formally, let \(G\) be an \(n \times m\) grid where each cell \(G_{ij}\) is either \(.) or \(#\). Determine whether a path exists from \(G_{11}\) to \(G_{nm}\) moving only to adjacent cells (up, down, left, right) that contain a dot (\(.)). If such a path exists, output YES; otherwise output NO.

Note that if either the start or the destination cell is blocked, then the answer is immediately NO.

inputFormat

The first line contains two integers \(n\) and \(m\) representing the number of rows and columns respectively. Following this, there are \(n\) lines, each containing a string of length \(m\) consisting of characters "." (traversable) and "#" (blocked).

outputFormat

Output a single line containing either YES if it is possible to reach from the start to the destination, or NO if it is not possible.

## sample
3 3
...
.#.
...
YES