This question already has an answer here:

Using Dijkstra algorithm, how can I find the next shortest path in a directed weighted graph? (When saying next, I mean that the next path must be heavier than the lightest path and not equal). The two paths can have some shared edges. I thought about storing for each vertex two fathers, and trying to build the second path from those fields, but I'm not sure how I can guarantee that I will create the desirable path. The implementation should stand in Dijkstra time complexity.

Any suggestions?


marked as duplicate by D.W., David Richerby, Rick Decker, Juho, Luke Mathieson May 18 '15 at 1:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.