# Loop counting -- what if the graph is not planar?

It is typically claimed that $\hbar$ counts the number of loops in a connected diagram. E.g., Weinberg's QFT, Vol.II, equation 16.1.10. This rests on the fact that for a diagram with $I$ internal lines and $V$ vertices, the number of loops is $$L=I-V+1\tag1$$

Now, this equation is essentially Euler's formula for planar graphs. Such a formula is only valid for planar graphs though, so how do we make sense of $(1)$ for non-planar graphs? How do we prove $\hbar$ counts the number of loops in an arbitrary (connected) diagram, regardless of whether it is planar or not?

They key point is that, as ACM points out in this answer of his, the formula for a general graph is just the Euler characteristic: $$V-E+F=2(1-g)$$ where $g$ is the genus of the graph. Planar graphs are, by definition, those with $g=0$.
Planar or not, it is easy to see that the number of independent loops of an arbitrary graph is $$L=F-1+2g$$ and therefore $$L=E-V+1$$ independently of $g$. $\tag*{$\square$}$
Note: the number of loops $L$ is $F-1$ (because the face "at infinity" is not counted as a loop) plus $2g$, because every handle allows you to add one cycle without intersections. Thus, $L=F-1+2g$, as claimed above.