The relation for elastic 1D collision become very simple if viewed from center of mass reference frame.

Before collision: two particles with mass and velocity as $m_1,\vec{v_1}$ and $m_2,\vec{v_1}$
After collision: the velocity have been changed to $\vec{v_1}'$ and $\vec{v_2}'$

The center of mass $X_{cm}= \frac{(m_1*x1+m2*x2)}{(m_1+m_2)}$
$\vec{V}_{cm}= \frac{(m_1*\vec{V_1}+m2*\vec{V_2})}{(m_1+m_2)}$

$\vec{V_1}'-\vec{V}_{cm}=\vec{V}_{cm}-\vec{V}_1=-(\vec{V}_1-\vec{V}_{cm})$

$\vec{V_2}'-\vec{V}_{cm}=\vec{V}_{cm}-\vec{V}_2=-(\vec{V}_2-\vec{V}_{cm})$