arraylist a , b , c are used to store the final output
let a = [ ] ; let b = [ ] ; let c = [ ] ; let ans ; function dfs ( w ) { if ( cd [ w ] == 0 ) return w ; if ( wt [ w ] < ans ) ans = wt [ w ] ; return dfs ( cd [ w ] ) ; }