Distance and shortest path