The trains take <u>57.4 s</u> to pass each other.
Two trains A and B move towards each other. Let A move along the positive x axis and B along the negative x axis.
therefore,

The relative velocity of the train A with respect to B is given by,

If the train B is assumed to be at rest, the train A would appear to move towards it with a speed of 170 km/h.
The trains are a distance d = 2.71 km apart.
Since speed is the distance traveled per unit time, the time taken by the trains to cross each other is given by,

Substitute 2.71 km for d and 170 km/h for 

Express the time in seconds.

Thus, the trains cross each other in <u>57.4 s</u>.