working succesive shortest path alg