Depending on how regular the streets are you could do the following
Make a distance map from all cities then sort the squares so that the furthest from any city is in front, then check from the front if there is a street.
// Setup
clear map
for all cities
set distance to zero
add to queue
while queue
pop square
for all neighbour squares
if unvisited
set distance to squares plus one
add neighbour squares to queue
Sort squares after decreasing distance
CheckDistance
for all sorted squares from furthest distance.
Check if street
return value
This will not work if any road serpentines.
This should give a reduced time if streets are common.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…