#K37747. Maze Path Validation
Maze Path Validation
Maze Path Validation
In this problem, you are given a maze represented as a grid of characters. Each cell in the grid can be one of the following:
- 'S': the starting cell
- 'E': the exit cell
- '#': a wall
- ' ' (space): an empty cell
You need to determine if there exists a valid path from the starting cell 'S' to the exit cell 'E'. The movement is allowed in the four cardinal directions: up, down, left, and right. More formally, if we denote the maze as a matrix , you need to decide whether there exists a sequence of moves starting from some cell (where ) and ending at some cell (where ) such that every move goes to an adjacent cell (i.e. from to , , , or ) and no move goes into a wall (i.e. a cell where ).
The input and output are handled using standard input and output respectively.
inputFormat
The input is given from standard input. The first line contains an integer denoting the number of rows in the maze. The following lines each contain a string representing a row of the maze. All rows have equal length.
outputFormat
Output a single line to standard output: print 'Yes' if there exists a valid path from 'S' to 'E', and 'No' otherwise.## sample
3
S##
#
E
Yes