arraylist a , b , c are used to store the final output
static List < Integer > a = new ArrayList < Integer > ( ) ; static List < Integer > b = new ArrayList < Integer > ( ) ; static List < Integer > c = new ArrayList < Integer > ( ) ; static int ans ; static int dfs ( int w ) { if ( cd [ w ] == 0 ) return w ; if ( wt [ w ] < ans ) ans = wt [ w ] ; return dfs ( cd [ w ] ) ; }