Breadth-first search on a matrix · Compiler
Breadth-first search on a matrix
Use breadth-first search to find the fewest moves from S to T in a maze. Each move goes to a side-sharing cell within the maze. Crossing a wall is forbidden.
- Input
- The first line contains r c (1 <= r,c <= 30, r*c >= 2). The next r lines each have c characters with no spaces. There is exactly one S and one T. Both are open. Each other cell is . for open or # for wall.
- Output
- Print the minimum number of moves, or -1 if T is unreachable.
Compiler Explorer runs your code when you run or check it.
Loading your exercise draft…