implement Dijkstra's algorithm for shortest path