Graph and weighted graph implementation.