#C4435. Shortest Path in a Maze

    ID: 47973 Type: Default 1000ms 256MiB

Shortest Path in a Maze

Shortest Path in a Maze

You are given a maze represented as a grid of characters, where each cell is either '.' indicating an open path, or '#' indicating a wall. The maze has dimensions \(m \times n\), and the top-left cell is the entry point (corresponding to \((1,1)\)) while the bottom-right cell is the exit (corresponding to \((m,n)\)).

Your task is to determine the minimum number of steps required to move from the start to the exit using only up, down, left, and right movements. If there is no valid path, output "IMPOSSIBLE".

Note: The maze may have obstacles that block the path. It is guaranteed that every cell in the maze is either '.' or '#'. Use a Breadth-First Search (BFS) approach to determine the shortest path.

inputFormat

The first line contains two space-separated integers \(m\) and \(n\) representing the number of rows and columns, respectively. The following \(m\) lines each contain a string of length \(n\) consisting of the characters '.' (open path) and '#' (wall), which together describe the maze.

outputFormat

Output a single line containing the minimum number of steps needed to reach the bottom-right cell from the top-left cell. If it is impossible to reach the exit, output "IMPOSSIBLE".

## sample
5 5
.....
..#..
..#..
..#..
.....
8

</p>