Driver code
public static void main ( String [ ] args ) { int N = 4 , K = 3 ; ArrayList < ArrayList < Integer > > adj = new ArrayList < > ( ) ; for ( int i = 0 ; i <= N + 1 ; i ++ ) adj . add ( new ArrayList < > ( ) ) ; addEdge ( adj , 1 , 2 ) ; addEdge ( adj , 2 , 3 ) ; addEdge ( adj , 3 , 4 ) ; DFS ( adj , N ) ; } }