TLE in one testcase of rat in a maze

https://ide.codingblocks.com/s/55527

how to optimize this code???

if you cant find a path through a point just mark it dead so that whenever in recussion you come across a dead point you will not check further path from dead point