#K80717. Pathfinding in a Grid Maze

    ID: 35593 Type: Default 1000ms 256MiB

Pathfinding in a Grid Maze

Pathfinding in a Grid Maze

You are given a rectangular grid representing a maze. Each cell in the grid is represented by one of the following characters:

  • S: the starting point
  • E: the ending point
  • B: an obstacle (blocked cell)
  • .: an open cell

Your task is to determine whether there exists a path from the starting point S to the ending point E by moving only up, down, left, or right, and not passing through any obstacles. Use a breadth-first search (BFS) or any suitable algorithm to solve the problem.

If there is a valid path, output Yes, otherwise output No.

Note: The coordinates of the grid are 0-indexed.

You may assume that the grid contains exactly one starting point and one ending point.

inputFormat

The input is given via standard input (stdin) in the following format:

 


...

Here, n and m are integers representing the number of rows and columns in the grid respectively, and each of the following n lines is a string of length m representing a row of the grid.

outputFormat

Output a single line to standard output (stdout) containing either Yes if there exists a path from S to E, or No otherwise.

## sample
4 4
S..B
..B.
B...
...E
Yes