You could have seen that beforehand : just change the language in the solutions page.
At least that gave you some training in C
I did it with radians from start, tried to exchange latitude/longitude (just in case), but still getting the same result for 5th test as @slava_spamec when all other tests are passed.
āEach line represents a one-directional routeāā¦ I didnāt notice. Thank you so much!
BTW, I ported my C++ dijkstra to Python, because I wanted to parse the middle part using csv module.
Also my code uses cool earth-distance calculation (using acos).
Finally I passed 100%. I was stuck at validation #4 āLarge Number of Stagesā, then I realised it was the stupid mistake of not converting degrees to radians and that I swapped latitude/longitude around.
So it was not a speed issue. My final solution used the A* algorithm, but my previous version of the code did far-from-optimal graph evaluations and would work too after fixing the above mistake.
Hello everyone!
Iām in a very strange situation: all tests pass, only one validator fails: āSeveral stagesā
Before correcting deg->rad, the āLarge number of stagesā failed too (thanks NewboO).
Now, I would like to make sure itās not a distance calculation issue. Here are the shortest distance I get for each test case, could someone tell me if these are correct, please?:
- 1.497570
- 0.335008
- 0.000000
- 2.302145
- 13.362002
- Impossible
If someone has any other idea or is experiencing the same situation, Iām really interested.
Many thanks!
Hi,
I pass all the tests and all the validators with my Python 3 code. Here are my testās distances :
- 1.4973071411893601
- 0.3348154821405869
- 0.0000000000000000
- 2.3022053696674263
- 13.362122315310147
- IMPOSSIBLE
They are pretty close to yours. So the problem comes certainly from somewhere else. Try to time your code and see if it could be a time-out problem. Maybe you need to optimize your code or use another algorithm. The most popular algorithms for shortest path problem are Dijkstra or A*.
Good luck!
I get:
1.4973071411888697
0.33481548214120577
0
2.3022053696676816
13.362122315309536
IMPOSSIBLE
My results are much closer to @bananaMixer than to you. I wonder if you might still have a slight calculation error somewhere and if perhaps the error is significant enough for one of the validators to be wrong.
- danBhentschel
Thank you all.
I replaced all floats by doubles and I get the same values as youā¦ then itās not a distance-calculation issue.
I checked for speed: it doesnāt exceed 30ms to complete any test. And it would be strange to pass āLarge number of stagesā and not āSeveral stagesā, wouldnāt it?
Then my issue is probably elsewhere (maybe if two ways connect with the same number of moves, one of the two being shorter in distance). Anyway, thank you very much!
Hi again!
Iām still working on my issue with āSeveral stagesā. I really donāt see where the problem might be: are names especially long? Are there special coordinates or special characters? Are UniqueID not always 4characters long?
Any help is welcome, thanks!
Hi there!
Do you have any suggestions, guys, how I can find the bug?
Iāve implemented Dijkstra with PriorityQueue, so it seems to be fast enough for Java (approx 120ms in āLarge number of stagesā for all steps - reading input, building maps and graph, finding shortest path).
It passes all the test cases, but fails in ā5 stops, 2 routesā. Iāve double checked degees to radians conversion and order of longitudes and latitudes. It seems OK for me. So It sounds not quite easy to find bug without seeing input data.
P.S.: Oh, Iāve just figured it out. I headed to bathroom after posting this message andā¦ gotcha! Just like in the āBack to the Futureā
Thanks so much !
i was failing the āLarge number of stagesā and could not understand why, i had the radians correctly figured out, the distance computation was correct.
The only thing i was missing for my A* to work was to correctly set the āgā to 0 for the starting node.
Hi Wingelin,
have you thought about the case when the current stop has no next stop (end of bus line) ?
Hey slavaā¦ literally exact same problem for me getting exact same output, using same language and algorithm, did you manage to fix this somehow?
Thanks for the comments about converting to radians! I had everything correct except that. Thatās pretty sneaky, but I suppose it is all there is you read it carefully.
Same for me! thanks for āsolutionā
Is there any special case? I have rewritten code 10 times by now and always fail only last test case, i convert angles to radians and use dijkstra.
I pass every test case using Dijkstraās algorithm, but only get 83% because of the ā5 stops, 2 routesā validator. I think I either inadvertently hard coded something or am just missing something really subtle. Any suggestions would be greatly appreciated
Have you converted the angles in radians?
Yes I have, using math.radians(x) in python.
Possible problem: I make the graph so that each route is directed from A to B, but search for a path as if it is can go either way. Canāt believe I didnāt notice that before. Very easy fix. Now I get 100%