I'm trying to solve the following exercise and I would be grateful if I could get a hint:
If the closed orientable surface $M_g$ of genus $g$ retracts onto a graph $X\subset M_g$, then the rank of $H_1(X)$ must be at most $g$.
Since there is a retraction $r:M_g\rightarrow X$ the composition $X\hookrightarrow M_g \stackrel{r}{\rightarrow} X$ is the identity and it hence induces the identity in homology, so in particular $H_1(X) \rightarrow H_1(M_g)=\mathbb{Z}^{2g} \rightarrow H_1(X)$ is an isomorphism and the first map is injective, so $rk(H_1(X))\leq 2g$.
Edited. Here's a full answer. Consider the cohomology with coefficients in a field (so from now on say $H^i(Y) = H^i(Y;\mathbb{R})$), and the induced composition of maps
$$ H^1(X) \xrightarrow{r^*} H^1(M_g) \xrightarrow{i^*} H^1(X) $$
Since $\text{id}^* = (ri)^* = i^* r^*$, $r^*$ is injective. Now consider the cup product pairing given by the evaluation of the cup product on a fundamental class of $M_g$ (for details see Hatcher, current online edition, p.250)
\begin{align} H^1(M_g) \times H^1(M_g) &\to \mathbb{R} \\ (\alpha,\beta) &\mapsto (\alpha \smile \beta)[M_g] \end{align}
This pairing is well known to be nondegenerate (by Poincaré duality) and skew-symmetric, and observe that it restricts to the zero pairing on the subvector space $r^*H^1(X) \simeq H^1(X)$ of $H^1(M_g)$, since for $\phi, \psi \in H^1(X)$
\begin{align} (r^*\phi \smile r^*\psi)[M_g] &= r^*(\phi \smile \psi)[M_g] \\ &= r^*(0)[M_g] \\ &= 0 \end{align}
where $0 = \phi \smile \psi \in H^2(X) = 0$ because $X$ is a graph (we were going to have to use this somewhere!).
The conclusion follows from the simple algebraic fact that a nondegenerate skew-symmetric bilinear form on a $\mathbb{K}$-vector space of dimension $n$ cannot restrict to the zero pairing on a subvector space of dimension $k>n/2$. Let $V \times V \to \mathbb{K}$ be this pairing, and $W$ the subspace to which it restricts to zero: pick a basis for $W$ and extend it to a basis of $V$. The resulting matrix of the bilinear form will then have a $k \times k$ zero block in the top left hand corner, which must be of dimension $\leq n/2$ for the matrix to be non singular (or otherwise the first $k$ columns would belong to an $n-k$-dimensional subspace of $\mathbb{K}^n$ and be therefore dependent).
Finally we apply the universal coefficient theorem, which implies $H_1(X;\mathbb{Z}) \simeq H^1(X;\mathbb{R}) \otimes \mathbb{Z}$ since all the homology is free abelian.