TLE in 3 test cases

TLE in 3 test cases

Please help me to optimize my code. When i tried this question using DFS, it gave me TLE in 4 test cases. Now, when i tried it with BFS, it is giving TLE in 3 test cases. Please help

code link: https://ide.codingblocks.com/s/304236