two trains are moving towards each other with velocitied u1 and u2 see that the distance between them is x.the condition for them to not collide is

they are on different tracks, or there is a break in the tracks between them.

You mention no deceleration, so I must assume that their speeds do not change.