← Back to topics
Topic

Evil Dijkstra

D
Daniel93
Does anybody knows how to solve this task?
D
Dgleich
Am I wrong or can't you just remove negative edges and find the shortest path?
Cuz isn't dijkstra going to visit each vertex at most once on path so the other condition is satisfied?
g
gates
edges are NONnegative, so that means there is no negative edges and simple dijkstra will do the work
D
Daniel93
yes, and that is not my problem. It says in case of tie, so if there are more than one shortest path I shoud output the lexicographical first shortest path.
D
Dgleich
Well in set or priority_queue you can first compare by distance and then by index?
D
Dgleich
You can backtrack the path similar like in DivInts you backtrack the result...
D
Daniel93
I think I got it. I will try to solve it. thanks :)
m
msantl
I need help with this task. When i find the shortest path and the smallest set of edges needed I just backtrack.

http://www.z-trening.com/submit.php?subm_stat=1&submit=7100076341
k
karakondzula
How to keep track of paths so that they can be compared?
m
msantl
Find the shorthest path from 0 to 1. Then run a DFS from 0, that takes lexicographically smaller neighbors first. When you get to 1 with the cost of the shorthest path then you found this path.
k
karakondzula
Thanks you, msantl. I solved it.
For those who didn't here is a little note:
if there is no path print "No path" not "No Path" like in example