Driver code
public static void Main ( String [ ] args ) { List < int > [ ] g = new List < int > [ 100005 ] ; for ( int i = 0 ; i < g . Length ; i ++ ) g [ i ] = new List < int > ( ) ; 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 ; Console . Write ( dfs ( g , root , - 1 ) ) ; } }