See my attached picture.
Remember that distance is speed*time, d = s*t.
[tex]d_{1} = s_{1}t = 50 \frac{mi}{h} * t \\
d_{2} = s_{2}t = 30\frac{mi}{h} * t \\ [/tex]
The distance for both cars total is 30. As a formula, this is
[tex]d_{1} + d_{2} = 30[/tex].
Putting the formulas together,
[tex]50t + 30t =30 \\ 80t = 30 \\ t = 3/8[/tex]
The time it takes is 3/8 hours.