This question already has an answer here:
I am trying to solve one graph traversing problem which might be classical to guys who are familiar with the topic. However, I am not. I have directed graph where nodes are cities and plane can fly from one to another. The network is quite complex. I have to find number of paths from e.g. Atlanta to Orlando with defined (zero, one, two…) number of stops. I do this by multiplying adjacency matrix exact number of times (repeated squaring) which gives distance matrix. The problem is how to eliminate redundant paths e.g. Atlanta-Boston-Atlanta-Orlando. This path has two stops which is O.K. from the algorithm point of view (if we need two stops) but makes no sense. Is there algorithm to eliminate such paths?