CSES Graphs- Monsters (Help needed)

Revision en1, by lalalalaaa..., 2020-10-02 15:34:48

I have started solving some problems related to graphs and most of the times i am not able to pass the testcases, either it is TLE or WA. I was solving MONSTERS question from cses Problem Link and was unable to figure to out why some testcases gave TLE.

What i have done-

1 Applied bfs and stored the min distance between each cell and the monster (M) cell.

2)Applied bfs for A and check whether there was a cell which was having less distance/ or more closer to A than any other M cell. And then checked whether it can reach to any border cell.

Link to My Code

It will be very helpful if anyone can let me know where i am going wrong.

Tags #graphs, #bfs

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English lalalalaaa... 2020-10-02 17:48:07 9
en1 English lalalalaaa... 2020-10-02 15:34:48 779 Initial revision (published)