CSES - Problem Labyrinth

Hello, in this problem I am getting TLE on some particular test cases where the maximum constraints are used. I tried using bfs and 2d array (char) (for maintaining the path) instead of map but still getting a TLE. I tried to keep my code clean. I hope you understand
Problem link = https://cses.fi/problemset/task/1193/
MY solution = https://cses.fi/problemset/result/1345686/