Well, first of all, I know that Dijkstra does not work for negative weights, and we can use Bellman-ford instead. But in the task, I was told that all edges have a weight of 0 to 1 (0 and 1 are not included). And the cost of the journey is actually a product.
So I thought, just take a magazine. Now all the edges are negative. Now I know that Dijkstra will not work for negative weights, but in this case all the edges are negative, so we cannot do something to make Dijkstra work.
I, although I multiply all the weights by -1, but then the shortest path becomes the longest path.
So in any case, I can avoid the Bellman-Ford algorithm.
The exact question: "Suppose that for some application the path cost is equal to the product of all the weights of the edges in the path. How would you use the Dijkstra's algorithm in this case? All the weights of the edges are from 0 to 1 (0 and 1 are not included)."
algorithm dijkstra shortest-path
George J. Adams
source share