To work out speeds you need to know the distance that each train has travelled.
So an equation needs to be formed
x = distance of slower train
x + 40 = distance of faster train (it is + 40 as the trains were travelling for 2 hours not one hour so 20 x 2 = 40)
so, x + x + 40 = 180
2x + 40 = 180
2x = 140
x = 70
Distance of slower train = 70 miles
Distance of faster train = 70 + 40 = 110 miles
To work out speed divide the distances by 2 as speed = distance/time
speed of slower train = 70/2 = 35mph
speed of faster train = 110/2 = 55mph