I f I am interpreting correctly, you must find a point P which minimizes the distances from the cities to the main road.

You can do this with similar triangles.

Solve for x and we get

You could derive a formula using Pythagoras and then differentiate, set to 0 and solve for x, but you'll get the same solution only with a lot more work.

Factor: