Solution (source code)

= Solution

A nonconstant holomorphic map $f:S\to T$ between compact connected <Riemann surfaces> has degree $d$ equal to the number of points in a fiber counted with local multiplicities. This number is independent of the target point. The <Riemann-Hurwitz formula> is
$$
\boxed{2g(S)-2=d(2g(T)-2)+\sum_{p\in S}(e_p-1),}
$$
where $e_p$ is the local degree at $p$.

Choose a polynomial $h(s)$ of degree $2g+2$ with distinct roots and take the smooth compactification of $t^2=h(s)$. The affine curve is nonsingular, since simultaneous vanishing of the partial derivatives would require $t=0$ and a repeated root of $h$. At infinity use $u=1/s$, $v=t/s^{g+1}$; the equation becomes $v^2=u^{2g+2}h(1/u)$, which has two smooth points above $u=0$ with nonzero $v$. These charts give a compact <hyperelliptic curve>, connected by the permitted path-connectedness result for the affine curve.

Projection to the $s$-sphere has degree two and simple ramification at the $2g+2$ roots of $h$, with no ramification at the two points at infinity. The <Riemann-Hurwitz formula> gives $2g(S)-2=-4+(2g+2)=2g-2$. Hence the surface has genus $g$, proving \b[every nonnegative integer occurs as the genus of a compact connected Riemann surface].