I have a directed graph that every node contain a letter and every edge has weight. I want to find the shortest path from a start node to an end node, that doesn't have letters showing not in sequence and has all the letters in it. For example:
I have those nodes: 1 - start node, 2- end node, 3 - 'A' letter, 4 - 'B' letter, 5 - 'B' letter, 6 - 'A' letter, 7 - 'B' letter.
And the edges are: 1 -> 3, 1 -> 4, 3 -> 5, 4 -> 5, 5 -> 6, 5-> 7, 6 -> 2, 7 -> 2.
The only valid paths for me are:
1 -> 3 -> 5 -> 7 -> 2 ('ABB'), 1 -> 4 -> 5 -> 6 -> 2 ('BBA').
I want to get the option of 'BBA' because it is the shortest. If I'll try using dijkstra, when i get to node number 6, my path will go through nodes number 3 and 5. Then i will set the weight of the edge (5 -> 6) to be Infinity for this path so it won't take this path. But, because it already got that the shortest path to node number 5 is through node number 3, it will choose the path 'ABB'. How can i get the correct path?
edit: what I want to find is a path, that the same letter can only be visited in 1 group. I mean, if I visit an 'A' group already and then went to 'B' group, i can't travel to another 'A' again. I can travel like this:
A->A->C->B->B
