Working implementation of Djikstras graph algorithm