Modifying a path into the shortest path