Let $G$ be a directed graph such that every edge is colored (red, yellow or green). I want to compute the shortest walk (possibly with repeated vertices) with the restriction that the colors are alternating: red, green, yellow, red, green , ..., etc (the starting color doesn't matter).
So far my idea is to create a new graph $G'$ such that is has a copy of each vertex (for each color). Then, by adequately placing every colored edge in the new graph I should be able to just run DFS/BFS in the new graph and get the answer. However, I don't know exactly how to correctly place the edges in the new graph $G$, or if this idea works.