Shortest paths solution