You will need to build an intermediate chart and run Dijkstra on this chart.
For the graph G = (V, E) create a new graph G' = (V', E') , with V' new set of vertices v_even and v_odd for each vertex v in v and E' set of vertices as follows: If (u, v) is an edge in G , then (u_odd, v_even) and (u_even, v_odd) are edges in G' with the same weight.
Obviously, the new graph has twice as many edges and vertices as the original graph.
Now, if you want to find the shortest path between s and t in G , just run Dijkstra on G' to find the shortest path between s_even and t_even .
Runtime is still O(|V| log |E|) .
source share