N1 - treasure hunting problem

https://www.codechef.com/viewsolution/1015102936

can someone point out what am I doing wrong ?
Sample cases are also working fine

@xade
What is your approch . Its a bfs problem.

I’m trying to use A* search, after sorting the goals according to ease of approach (not the closest to the goal before)