Implementation of graph and weighted graph.