Gravity due to any planet on its surface is given by
[tex]g = \frac{GM}{R^2}[/tex]
here we have
[tex]M = \rho*\frac{4}{3}\pi R^3[/tex]
[tex]g = \frac{G*\rho*\frac{4}{3}\pi R^3}{R^2}[/tex]
[tex]g = \frac{4}{3}*\rho*\pi*G*R[/tex]
Now since the gravity due to both planets are same
[tex]g_x = g_e[/tex]
[tex]\frac{4}{3}*\rho_e*\pi*G*R_e = \frac{4}{3}*\rho_x*\pi*G*R_x[/tex]
[tex]\rho_e*R_e = \rho_x*R_x[/tex]
now we have
[tex]\frac{r_x}{r_e} = \frac{\rho_e}{\rho_x}[/tex]
so above is the ratio of the radius