first implementation of Dijkstra SP