Dijkstra implementation for dm