Блог пользователя Destroyer_x

Автор Destroyer_x, 4 месяца назад, По-английски

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

My Code

Thanks.

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

»
4 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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)