Add check for unconnected pairs in shortest path