implemented dijkstra's algorithm