Distance while traveling uphill and downhill is same. Let it be $d$ miles.
$\mathrm{Speed = }\dfrac{\mathrm{Distance}}{\mathrm{Time}}$
Time required to travel uphill will be $t_1 = \dfrac{d}{X}$ hrs.
Time required to travel downhill will be $t_2 = \dfrac{d}{Y}$ hrs.
Now, $t_1 + t_2 = Z \implies d\left(\dfrac{1}{X} + \dfrac{1}{Y}\right) = Z \implies d = \dfrac{ZXY}{X+Y}$ miles
Plugging in $X= 20, Y = 30, Z = 1$, we get $d = \dfrac{20\times30}{50} = 12$ miles.