I have been stuck on this problem for two days now and still no progress. Basically the problem is as follows: Given an undirected simple weighted and connected graph, we have to find the shortest walk from a given source to a given destination while visiting at least one vertex from a given set, A and at least one vertex from the set B with the added constraint that the vertex from set B should always come after visiting the vertex from set A. Set A and B are disjoint and there can be vertices in the graph which neither belong to A nor B. There is a single source and destination vertex.
I tried decomposing the shortest path into one which visits a vertex, v in A from source, then from v to another w in B and then from w to destination. This can be done using 3 passes of Dijkstra with different starting vertices respectively. But, I would have to choose the minimum such v resulting in O(VElog(V)) complexity where V = number of vertices and E = number of edges. I am terribly stuck on how to do this in O(E*log(V)), since the question asks so, i.e. using only O(1) Dijkstra runs. Can anybody please help me?
Edit: We can't construct a new graph or modify it as some people are suggesting to construct a level graph. I have to modify the Dijkstra routine somehow to solve this. Graph. Blue vertices are the set A, purple ones set B. Home is 0 and Destination is 8 In this graph(see link) for example, the shortest walk should be: 0 -> 1 -> 0 -> 3 -> 6 -> 7 -> 8 with total cost = 6