Let be a directed graph, and let
be an edge-coloring in red and blue. Let s,t be vertices in G. Find a path from s to t (if exists) so that the number of color changes along this path is minimal.
I have tried to do as follows:
- Let
be the graph obtained by removing all the blue-colored edges of G. Let
be the graph obtained by removing all the red-colored of G.
- Let
be the strongly connected graph of
, computed using this algorithm.
- Let
be the strongly connected graph of
, computed using this algorithm.
- Color the vertices of
in red, and color the vertices of
in blue.
- Let
be the graph obtained by merging
with
.
- Define the weight of each (existing) edge in G' as 0.
- For each
such that u belongs to the strongly connected component
and v belongs to the strongly connected component
do as follows:
- Use Dijkstra algorithm to find a shortest path from the blue strongly connected component of s, to both the blue and red strongly connected components of t.
- Use Dijkstra algorithm to find a shortest path from the red strongly connected component of s, to both the blue and red strongly connected components of t.
- Let p denote the shortest path among the four we have just found. (namely, p has minimal number of color alternates). p is a series of strongly connected components. Expand each of them using DFS, to find a corresponding path in G.
This algorithm can run in O(E+V*log(v)). Can it be improved or simplified?