dijkstra implementation for homework