Refine the code of Dijkstra algorithms