The energy that we want to conserve is given by:
\begin{equation}
E(t) = E_1(t) + E_2(t) = \frac{m_1}{2}\int_0^{\infty}(u_t^2 + c_1^2u_x^2)dx + \frac{m_2}{2}\int_{-\infty}^{0}(u_t^2 + c_2^2u_x^2)dx
\end{equation}
To make the energy conserved, we take the time derivative of $E(t)$ and set it equal to zero. So:
\begin{equation}
\frac{dE}{dt} = \frac{m_1}{2}\int_0^{\infty}(2u_tu_{tt} + c_1^22u_xu_{xt})dx + \frac{m_2}{2}\int_{-\infty}^0(2u_tu_{tt} + c_2^2u_xu_{xt})dx
\label{eq:timeder}
\end{equation}
Doing integration by parts on the second term of the first integral (where the result will extend to the second term of the second integral), we get:
\begin{equation}
\int_0^{\infty}u_xu_{xt}dx = u_xu_t|_0^{\infty}-\int_0^{\infty}u_{xx}u_tdx
\label{eq:parts}
\end{equation}
Plugging \ref{eq:parts} into \ref{eq:timeder}, we get:
\begin{equation}
\frac{dE}{dt} = m_1 \left( \int_0^{\infty}u_tu_{tt}dx + c_1^2u_xu_t|_{-\infty}^0 - c_1^2\int_0^{\infty}u_{xx}u_tdx \right) + m_2 \left( \int_{-\infty}^0u_tu_{tt}dx + c_2^2u_xu_t|_0^{\infty} - c_2^2\int_{-\infty}^0u_{xx}u_tdx \right)
\label{eq:terms}
\end{equation}
For each term, we can combine the integrals. For example, for the first term we have:
\begin{equation}
m_1 \int_0^{\infty} \left( u_tu_{tt}dx - c_1^2u_{xx}u_tdx \right) = m_1 \int_0^{\infty} \left( u_t \left(u_{tt} - c_1^2u_{xx} \right) dx \right)
\label{eq:rearrange}
\end{equation}
Recall from the problem that $u_{tt} - c_{1/2}^2u_{xx} = 0$. Therefore we get:
\begin{equation}
\frac{dE}{dt} = m_1c_1^2u_xu_t|_0^{\infty} + m_2c_2^2u_xu_t|_{-\infty}^0
\end{equation}
\begin{equation}
\frac{dE}{dt} = m_1c_1^2u_x(\infty)u_t(\infty) - m_1c_1^2u_x(0)u_t(0) + m_2c_2^2u_x(0)u_t(0) - m_2c_2^2u_x(-\infty)u_t(-\infty)
\end{equation}
Here we must assume that the solutions are fast-decaying, so the terms at infinity go to zero. We then get:
\begin{equation}
\frac{dE}{dt} = - m_1c_1^2u_x(0)u_t(0) + m_2c_2^2u_x(0)u_t(0)
\end{equation}
Since we wanted the energy to be conserved, we set this to zero. We can then solve for the required relation between $m_1$ and $m_2$.
\begin{equation}
- m_1c_1^2u_x(0)u_t(0) + m_2c_2^2u_x(0)u_t(0) = 0 \longrightarrow m_1c_1^2u_x(0)u_t(0) = m_2c_2^2u_x(0)u_t(0)
\end{equation}
\begin{equation}
\longrightarrow m_1c_1^2 = m_2c_2^2 \longrightarrow m_1 = \frac{m_2c_2^2}{c_1^2}
\end{equation}
Therefore we can conclude that for the energy to be conserved, $m_1:m_2 = \frac{c_2^2}{c_1^2}$.