Codeforces 648 Div2 D

Can someone please tell me why am i receiving tle on test 9 in Problem D (Solve the maze)
Link to the problem : https://codeforces.com/contest/1365/problem/D
Link to my solution: https://codeforces.com/contest/1365/submission/84673202

Is it because of dfs?

if you check via dfs every time you will get a TLE !!
check mine-> https://codeforces.com/contest/1365/submission/83171044

1 Like

You can only do DFS/BFS once by starting at the last cell in the last row and last column. Then check if you can visit all Good places or not, instead of checking if you can reach last cell for every Good place.

1 Like

Got it.
Thank You.