Final version for Dijkstra