I have a shortest path problem that I need to solve, and I'm fairly certain that there should be a efficient solution I have this fun representation of a graph:
as ascii:
input
. N N N N N N
W 7 9 8 8 7 5 N . . . N N N
W 2 2 2 1 1 6 6 N N N 5 5 N E
W 1 2 3 2 2 2 2 4 5 5 4 2 5 E
. S S S 3 3 3 2 6 5 4 2 2 2 E
. . . . S S 2 2 2 2 3 7 2 2 E
. . . . . . S 2 3 2 7 7 7 7 E
. . . . . . . S 7 7 7 7 7 7 E
. . . . . . . S 7 7 7 S S 7 E
. . . . . . . . S 7 S . . S
. . . . . . . . . S
Output:
35
I need to find the shortest a path from one of the 'E' spots to one of the 'W' spots, walking over the numbered spots. We are not able to walk on the 'N' and 's' spots. When we stand at a spot, we´re able to walk up, down,left and right. I need to find the shortest path in terms of the numbered squares that I am walking on. Here is a more simple example:
I would create a double directed DAG with all edges going towards a numbered edge, having that number as weight, and all edges going to E or W having weight 0:
my attempt
Now this is a case of finding a shortest path from multiple sources to muliple sinks. My naive thought is that I could run Dijkstra from every w, to every E. This would however run in something like O(W*dijkstra^E) (where E is the amount of E nodes)
Is there any smarter way to do a multi-source multi-sink dijsktra?


