Calculate shortest path.