Let the lengths of the trains be 'a' m and 'b' m respectively.
Since, the trains are approaching in the first case,
Relative speed = 20 + 30 = 50 m/s.
Distance covered = (a + b) m.
Given, time taken = 10 s
∴ a + b = 50*10 = 500..(i)
Length of the third train = (a - b) m
∴ Distance travelled by the third train while crossing the man = (a - b + 100) m
∴ Relative speed = 43 - 3 = 40 m/s
Given, Time taken = 5 s
∴ a - b + 100 = 40*5
=> a - b = 100..(ii)
Adding the two equations, we get
a = 300 m and b = 200 m
∴ Ratio of the length of the trains = 300:200 = 3:2