Two cars tied with a spring 
A spring of spring constant $k$ is tied with two cars of masses $m_1$ and $m_2$ with a rope. As a result, the spring is compressed by $x$ meters. Initially, assume that they are at rest. Suddenly, the rope is cut. Find the velocities of the two cars with which they would depart.


Originally, my approach of dealing with it was energy and momentum conservation, so I thought of using
$$\frac{1}{2}kx^2=\frac{1}{2}m_1{v_{1}}^2+\frac{1}{2}m_2{v_{2}}^2 \\ m_1v_1+m_2v_2=0$$
but it turned out my approach was wrong.
The book had this equation
$$\frac{1}{2}m_1{v_{1}}^2=\frac{1}{2}\frac{m_2}{m_1+m_2}kx^2$$
and they mentioned that the were considering distances with respect to center of mass. They didn't explain how they jumped into the equation and I also didn't understand how they deduced the equation and what they mean by considering distances with respect to center of mass as I don't have much experience regarding the center of mass. Please help.
 A: With centre of mass, this question becomes easier. The mentioned answer might be derived using this concept. Actually, you must need to know kinetic energy wrt centre of mass frame:
$$K = \sum_i^n \frac{1}{2} m_i {v^\prime_i}^2 + \frac{1}{2}M_{\text{total}}V_{cm}^2$$
I am leaving derivation and more information here
Here $v_i^\prime$ is velocity of $i$'th particle wrt centre of mass frame.  $$v^\prime_i=v_i-V_{cm}$$
For two body situation our main equation becomes $$K=\frac{1}{2} \frac{m_1m_2}{m_1+m_2}v_{rel}^2+\frac{1}{2}MV_{cm}^2$$
where $v_{rel}=|v_2-v_1|$
Now coming to our question, here no external force is acting, so centre of mass remains at rest. Only force acting is spring force, which is counted as internal. So $V_{cm}=0$, which reduces to: $$m_1v_1+m_2v_2=0\,\,\, (1)$$
Now our equation of kinetic energy becomes $$ K=\frac{1}{2} \frac{m_1m_2}{m_1+m_2}v_{rel}^2\,\,\,(2)$$
And now $\frac{1}{2}kx^2=K$
Using equations (1), (2) we can find $v_1,v_2$.
Hope it helped!
A: Since the center of mas does not move, measuring the velocities relative to the center of mass does not change the velocities. Solve your momentum equation equation for $v_2$. Put that in the energy equation and solve for (1/2)$m_1({v_1}^2)$. You get the given result.
