To solve this problem, let us say that
A = starship enterprise
B = klingon ship
Assuming that the starship enterprise comes to a constant deceleration, then the average velocity would be:
vA = (vAi + vAf) / 2 where vAf = 0 since it must come to a stop
vA = (50 + 0)/2
vA = 25 km/s
Therefore the distance that A must travel before it comes to
a stop is 100 km plus the distance of B that it travels within that time:
dA = dB + 100
25t = 20t + 100
5t = 100
t = 20 s
So
dA = 25t = 25(20) = 500 km
and
dA = vAi * t + 1/2 a t^2
500 = 50(20) + 1/2 a (20)^2
a = -2.5 km/s^2
So the enterprise needs to decelerate at -2.5 km/s^2 to avoid collision.