#C11680. Reachability in a Grid

    ID: 41023 Type: Default 1000ms 256MiB

Reachability in a Grid

Reachability in a Grid

Given an \(N \times M\) grid, where each cell is either open or blocked, determine if there exists a path from the top-left corner (cell \((1,1)\)) to the bottom-right corner (cell \((N,M)\)).

The grid is represented using characters: a dot ('.') denotes an open cell, and a hash ('#') denotes a blocked cell. You can move up, down, left, or right from a given cell. Note that both the starting cell and the destination cell must be open.

If a valid path exists, output YES; otherwise, output NO.

inputFormat

The first line contains two integers \(N\) and \(M\) separated by a space, representing the number of rows and columns in the grid, respectively.

The following \(N\) lines each contain a string of length \(M\) consisting of the characters '.' and '#' representing the grid.

outputFormat

Output a single string: YES if there is a valid path from the top-left corner to the bottom-right corner; otherwise, output NO.

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