Modified shortest path function
to return the path distance.