Partial implementation of Dijkstra