implemented Dijkstra's Algorithm