Source: https://www.ime.usp.br/~pf/graph-exercises/text/ETG.pdf