Answer
The magnitude of the constant deceleration is $~~0.994~m/s^2$
Work Step by Step
We can express the train's speed in units of $m/s$:
$v_t = (161~km/h)(\frac{1~h}{3600~s})(\frac{1000~m}{1~km}) = 44.72~m/s$
We can express the locomotive's speed in units of $m/s$:
$v_l = (29.0~km/h)(\frac{1~h}{3600~s})(\frac{1000~m}{1~km}) = 8.06~m/s$
Let the deceleration period be time $t$
To avoid a collision, the train needs to slow down to the same speed as the locomotive.
We can find an expression for $t$:
$v_f = v_i+at$
$t = \frac{v_f-v_i}{a}$
$t = \frac{8.056~m/s-44.72~m/s}{a}$
$t = -\frac{36.66~m/s}{a}$
In this time $t$, the locomotive travels a distance of $d_l = (8.06~m/s)(t)$
To avoid a collision, the train can travel a total distance of $D+d_l$ as it decelerates.
We can find the rate of deceleration $a$:
$D+d_l = v_i~t+\frac{1}{2}at^2$
$D+8.06~t = 44.72~t+\frac{1}{2}at^2$
$676+8.06~(-\frac{36.66}{a}) = 44.72~(-\frac{36.66}{a})+\frac{1}{2}a(-\frac{36.66}{a})^2$
$676-\frac{295.5}{a} = -\frac{1639.4}{a}+\frac{672.0}{a}$
$676~a-295.5 = -1639.4+672.0$
$676~a = -671.9$
$a = -\frac{671.9}{676}$
$a = -0.994~m/s^2$
The magnitude of the constant deceleration is $~~0.994~m/s^2$