normal_cf_user's blog

By normal_cf_user, history, 22 months ago, In English

In the problem CSES-Labyrinth I have written a simple BFS solution but still getting TLE , The solution is O(N*M) solution means it should work fine , but don't know why I'm getting TLE. Any Help is appreciated.

My Submission : Here

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
22 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I think you have overcomplicated here you are storing the path at each point leading to TLE here i think here you can use the bfs, here you just need to store a boolean vector for visited and you need to store the parent value also so that you can trace the path. The point here is we know that the bfs always gives the shortest path as soon as we reach the ending point we will simple backtrack through the parent in order to the get the path.