Driver code
public static void main ( String [ ] args ) { @ SuppressWarnings ( " unchecked " ) Vector < Integer > [ ] g = new Vector [ 100005 ] ; for ( int i = 0 ; i < g . length ; i ++ ) g [ i ] = new Vector < Integer > ( ) ; int edges = 6 ; g [ 18 ] . add ( 7 ) ; g [ 7 ] . add ( 18 ) ; g [ 18 ] . add ( 15 ) ; g [ 15 ] . add ( 18 ) ; g [ 15 ] . add ( 2 ) ; g [ 2 ] . add ( 15 ) ; g [ 7 ] . add ( 4 ) ; g [ 4 ] . add ( 7 ) ; g [ 7 ] . add ( 12 ) ; g [ 12 ] . add ( 7 ) ; g [ 12 ] . add ( 9 ) ; g [ 9 ] . add ( 12 ) ; int root = 18 ; System . out . print ( dfs ( g , root , - 1 ) ) ; } }