#K34267. Maze Path Existence

    ID: 25272 Type: Default 1000ms 256MiB

Maze Path Existence

Maze Path Existence

Given a 2D grid maze of dimensions \( n \times m \), determine if there exists a valid path from the start cell 'S' to the end cell 'E'. You can move in four cardinal directions (up, down, left, right) and may only traverse through open cells represented by '.' or the end cell 'E'. Obstacles in the grid are represented by '#' and cannot be traversed.

Note: The maze contains exactly one start 'S' and one end 'E'. Your task is to determine whether there exists a sequence of valid moves that connects 'S' and 'E'.

inputFormat

The first line contains two space-separated integers \( n \) and \( m \) denoting the number of rows and columns of the maze respectively. This is followed by \( n \) lines, each containing a string of length \( m \). Each character in the string is one of 'S', 'E', '.', or '#'.

outputFormat

Output a single line with True if there exists a path from 'S' to 'E', otherwise output False.

## sample
5 5
S....
.#.#.
.....
.#.#.
....E
True

</p>