#t455. 走出迷宫
走出迷宫
Escaping the Maze
Problem Background
Special for beginners, ^_^
Problem Description
When you stand inside a maze, the criss-crossing paths easily make you lose your sense of direction. If you have the map of the maze, things become much simpler.
Suppose you already have the blueprint of an maze. Find the shortest path from the start to the exit.
Input Format
The first line contains two integers and (): the number of rows and columns of the maze.
Then follow lines, each a string of length , describing the layout of the whole maze. The characters mean:
.— open ground#— wallS— startT— exit
Output Format
Print the minimum number of steps from the start to the exit.
Sample Input
3 3
S#T
.#.
...
Sample Output
6
Constraints
.
Time limit s, memory KiB per test case.
Hint
- Standard BFS over a grid; the first time you expand
Tis the shortest distance fromS. - Adjacent cells are only the four orthogonal neighbours; walls (
#) are not traversable.