Apply the Pythagorean Theorem here.
Square the lengths of the 2 shorter sides: (20 mi)^2 and (40 mi)^2. Correct results are 400 and 1600. Combine these: obtain 2000.
Then the length of the diagonal (which is the distance between the 2 cities) is
sqrt(2000) = sqrt(400)*sqrt(5) = 20 sqrt(5) (answer)