Kevin is trapped in a maze filled with many rooms and needs your help to escape!
The maze can be modelled as an
Looping around is defined as, from any room
Given that Kevin starts at the top left corner and the exit is at the bottom right corner, print the minimum number of times he needs to teleport to reach the exit. If it is impossible, print FOREVER
to signify that Kevin will never escape the maze!
Input Specification
The first line will contain positive integers
The next
Output Specification
Print the minimum number of times Kevin needs to teleport to reach the exit. If it is impossible to reach the exit, print FOREVER
.
Subtasks
Subtask 1 [40%]
All integers in the input will be in the range
Subtask 2 [60%]
No additional constraints.
Sample Input 1
3 3
2 4 3
1 1 2
6 5 8
Sample Output 1
3
Explanation for Sample Output 1
There are multiple solutions. In one solution, Kevin teleports left two rooms looping around to
Sample Input 2
3 3
2 5 9
1 9 3
6 3 8
Sample Output 2
FOREVER
Explanation for Sample Output 2
There is no way to get from
Comments
Can someone check my code? I can't seem to get past Batch #1. I'm probably missing something really obvious.
Grid should be of type int, not char.
:facepalm: Thanks for the help.