edited shortest path algorythm