Destroyer_x's blog

By Destroyer_x, 4 months ago, In English

Can Someone Please Explain why this code is giving MLE at test case 45. 251218571

My Code

Thanks.

  • Vote: I like it
  • +3
  • Vote: I do not like it

»
4 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Your solution is doing BFS in brute force way, ignoring the constraints, and pushing so many nodes into the deque and dist map. If I'm not wrong, you'll push all possible pairs of {station, subway lines} that are connected. No wonder it's MLE and eventually TLE.

You need to change your approach. I left a hint in a comment if you need it. (It's based on editorial)