Link of the question is here
MySubmission:30167878
Hello fellow coders,
I am facing a problem in 500-B problem. All the required links are given and the problem with my solution is that I am getting TLE. I am really unable to find what is wrong with my solution. If anybody could help me out then please help me.
I am sorry if anyone get annoyed thinking that I am asking a very easy question. I really need help as I am coding without any coach. Please help me out.
Thanks in advance
You made a pretty simple mistake. When you insert into your stack, you check to see whether it was visited right? However, as you insert it into your stack, you do not change the status of the vertex into "visited." This allows the same vertex to be inserted into the stack multiple times, causing your time complexity to boom. I was too lazy to read the problem, so I just skimmed through your code and found that small error. Your code after the change