This problem is best solved in the reference frame of one of the trains. Find the initial relative velocity of one train with respect to the other, the relative acceleration of one train with respect to the other and the relative displacement of one train with respect to other as they pass each other. Use the second equation of motion with constant acceleration to find the required time.
The relative displacement of the trains is
S=100 + 100 = 200 M.
The initial velocity u of one train relative to the other train
Relative acceleration, a = (30+20)cm/s2 = 0.5m/s2 If
't' is the time taken to cross each other,