arraylist a , b , c are used to store the final output
static List < int > a = new List < int > ( ) ; static List < int > b = new List < int > ( ) ; static List < int > c = new List < int > ( ) ; 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 ] ) ; }