Does anybody knows how to solve this task?
Evil Dijkstra
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?
Cuz isn't dijkstra going to visit each vertex at most once on path so the other condition is satisfied?
edges are NONnegative, so that means there is no negative edges and simple dijkstra will do the work
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.
Well in set or priority_queue you can first compare by distance and then by index?
You can backtrack the path similar like in DivInts you backtrack the result...
I think I got it. I will try to solve it. thanks :)
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
http://www.z-trening.com/submit.php?subm_stat=1&submit=7100076341
How to keep track of paths so that they can be compared?
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.
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
For those who didn't here is a little note:
if there is no path print "No path" not "No Path" like in example