Problem in solving a problem on SPOJ

bfs
graph
maze
shortest-path

#1

How to nail this questionthis question