I have a jorney between A and B which has different paths to end it. The paths are defined by the initial and final kilometers:
path 0 -> (0, 10)
path 1 -> (10, 25)
path 2 -> (10, 15)
path 3 -> (15, 20)
path 4 -> (20, 30)
path 5 -> (25, 35)
path 6 -> (30, 35)
path 7 -> (35, 40)
path 8 -> (40, 50)
As you can see, there are paths that overlap. In fact, we can get the list of overlapped paths:
path 0 -> NONE
path 1 -> 2,3,4
path 2 -> 1
path 3 -> 1
path 4 -> 1,5
path 5 -> 4,6
path 6 -> 5
path 7 -> NONE
path 8 -> NONE
What I want to get is all the possible routes without overlapped paths in the route but only one should be taken. Is there an algorithm that can solve this problem? I tried to implement with recursion or with an auxiliar data structure like a stack, but I find quite difficult to obtain a list with the final possible routes, also I tried to inverse the problem and try to obtain a list of the paths discarded, which are:
route 0-2-3-4-6-7-8 -> [1,5] discarded
route 0-2-3-5-7-8 -> [1,4,6] discarded
route 0-1-6-7-8 -> [2,3,4,5] discarded
route 0-1-5-7-8 -> [2,3,4,6] discarded