Proof (Riemann-Hurwitz formula)

By the local mapping theorem, the set of ramification points is discrete. As $X$ is compact, it is finite. Therefore the formula only involves a finite sum.

For each $y\in Y$, as in the proof of the valency theorem, find an open neighbourhood $V_y$ of $y$ such that $f\inv(V_y) = \bigsqcup_{x\in f\inv(y)} U_{x}$ for disjoint open sets $U_x$, and $f|_{U_x\setminus \set{x}}: U_x \setminus \set{x}\to V_y\setminus \set{y}$ is $z\mapsto z^{d_x}$ in some charts. By compactness of $Y$, find a finite open cover $\set{V_i}$ by these $V_y$'s.

Take any triangulation $\mathcal{T}_Y$ of $Y$. By subdividing triangles, we can assume all finitely many ramification points are vertices in $\mathcal{T}_Y$. Furthermore, by compactness, subdivide so that each triangle lies within some $V_i$. (Apply the Lebesgue number lemma and the shrinking mesh of barycentric subdivision.)

Consider the preimage $\mathcal{T}_X$ of $\mathcal{T}_Y$ under $f$. By construction, if $Δ$ is a triangle in $\mathcal{T}_Y$ where a vertex $y$ is a branch point (by construction there can be at most one such vertex), for each $x\in f\inv(y)$, there are $d_x$ many triangles in $f\inv(Δ)\cap U_x$ sharing the vertex $x$. Therefore $f\inv(Δ)$ consists of $\sum_{x\in f\inv(y)} d_x = n$ triangles by valency theorem. If all vertices of $Δ$ are unramified, then $f\inv(Δ)$ consists of $n$ many disjoint triangles, one in each $U_x$ for $x\in f\inv(y)$. Hence the number of faces and edges of $\mathcal{T}_X$ and $\mathcal{T}_Y$ are related by $$ \begin{align*} F_X = n \cdot F_Y, \quad E_X = n \cdot E_Y. \end{align*} $$

Now we count vertices. Note by valency theorem $$ \begin{align*} n = \sum_{x\in f\inv(y)} d_x = \#f\inv(y) + \sum_{x\in f\inv(y)} (d_x - 1) \end{align*} $$ so $$ \begin{align*} V_X = \sum_{\text{vertex $y$ of $\mathcal{T}_Y$}} \#f\inv(y) = \sum_{\text{vertex $y$ of $\mathcal{T}_Y$}} \Bigl(n - \sum_{x\in f\inv(y)} (d_x-1)\Bigr) = n \cdot V_Y - \sum_{x\in X} (d_x - 1). \end{align*} $$

Combining yields the Riemann-Hurwitz formula.