TreeSet is used to get clear understand of graph .
HashMap < Integer , TreeSet < Integer > > graph ; static int v ; public Graph ( ) { graph = new HashMap < > ( ) ; for ( int i = 0 ; i < v ; i ++ ) { graph . put ( i , new TreeSet < > ( ) ) ; } }