Source: https://people.eecs.berkeley.edu/~nirkhe/cs38notes/graph.pdf