Calculate shortest path