We know that, when the trains are moving in the same direction,
Relative speed= Difference between the speed of train
and total distance for crossing each other = Sum of the length of train
Therefore, Relative speed = 72 km/hr - 54 km /hr = 18 km/hr
Relative speed in m/sec = 18 km/hr x 5/18 = 5 m/sec
and Total distance = 200m + 300m = 500m
and Total time taken to cross each other = Total distance in meter/ Relative speed in m/sec
= 500 m / (5 m/sec) = 100 sec