#K70507. Maze Runner: Path to Exit
Maze Runner: Path to Exit
Maze Runner: Path to Exit
You are given a maze represented as a 2D grid of integers. Each cell in the maze can be:
- 0: An open path.
- 1: A wall, which cannot be traversed.
- 2: The exit.
You are also given a starting coordinate (row, column). Your task is to determine whether there is a path from the starting position to the exit. Movement is allowed in the four cardinal directions: up, down, left, and right. Once you visit a cell, mark it as visited to avoid cycles.
Input Format: The input is read from standard input. The first line contains two integers n and m representing the number of rows and columns. The following n lines each contain m integers describing the maze. The last line contains two integers representing the starting row and column.
Output Format: Output either True
if there is a valid path from the starting point to the exit, or False
if not.
The problem can be solved using a DFS (Depth-First Search) strategy.
inputFormat
Standard input contains:
n m row1_element1 row1_element2 ... row1_element_m row2_element1 row2_element2 ... row2_element_m ... row_n_element1 row_n_element2 ... row_n_element_m start_row start_col
For example:
4 4 0 1 0 0 0 1 1 0 0 0 0 1 1 1 2 0 0 0
outputFormat
Output a single line True
if there is a path from the start to the exit; otherwise, output False
.
4 4
0 1 0 0
0 1 1 0
0 0 0 1
1 1 2 0
0 0
True