implementing Dijkstra using greedy alorithm