Problem "Returning Home" (1422D), TLE on Test 5 [SOLVED]

Revision en2, by ynnuface, 2020-10-10 13:07:19

Basically for every node I calculate the 4 closest nodes in all four directions, so the number of edges should be at most 4*M, right?

After that I run Dijkstra but for some reason I get TLE on test 5, I spent a lot of hours trying to see why but with no success, that's why I'm asking for some help, I just don't know what's wrong with my implementation.

Code link: https://codeforces.com/contest/1422/submission/95066276

Edit: Nvm, I'm very stupid. When I ran Dijkstra, the set was like this: {node, distance} when it should have been {distance, node}, so everything was sorted after the value of the nodes instead of the distance, so that's the reason for TLE. Also on line 14 I made a small typo: "ans=abs(sx-fx)+abs(sy+fy);" instead of "ans=abs(sx-fx)+abs(sy-fy);", so after fixing TLE that gave me WA on test 5.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English ynnuface 2020-10-10 13:07:19 407
en1 English ynnuface 2020-10-10 12:30:06 474 Initial revision (published)