### Kaneki-kun's blog

By Kaneki-kun, 5 weeks ago, ,

While I was trying to solve a problem with dijkistra, something strange happened. I got an MLE test 2, but I discovered that after I changed some lines, which are not supposed to cause an MLE, with the corresponding lines in an AC code , it got AC. I'm now stuck in trying to understand why that happened!

The problem

The MLE solution

The AC solution

The two codes are identical. I just commented the call of a function and called the other in main!

• +10

 » 5 weeks ago, # | ← Rev. 2 →   +1 "The two codes are identical, I just replaced a function with a completely different function."The functions DIST and dis are not equivalent. Namely DIST (which is where your code failed) can return negative values. I am not going to verify it but I suspect that if you use DIST your graph will have a negative cycle which causes your Dijkstra to go to an infinite loop.Here are the three first test cases of test 2. Even there, your code fails so it should be enough to debug. Test case3 8 200 100 20 10 10 1 80 20 20 0 20 90 120 0 30 8 150 1 20 1 0 0 20 1 100 0 10 10 140 1 20 1 180 1 9 200 100 20 10 10 1 80 20 20 0 20 90 120 0 30 8 150 1 20 1 0 0 20 1 100 0 5 10 130 1 15 1 135 1 20 1 180 1 8 200 100 20 10 10 1 80 20 20 0 20 90 120 0 30 8 150 1 20 1 0 0 20 1 100 0 5 10 130 1 15 1 135 1 
•  » » 5 weeks ago, # ^ |   0 Thank you very much