Source: https://web.stanford.edu/class/cs97si/06-basic-graph-algorithms.pdf