update logic and code in the Dijkstra algorithm