Dijkstra's algorithm to find shortest path