Implmentation of Dijkstra's algorithm