implement Graph.java as required