Add edges
for ( let i = 0 ; i < N - 1 ; i ++ ) { let u = edges [ i ] [ 0 ] , v = edges [ i ] [ 1 ] , w = edges [ i ] [ 2 ] ; adj [ u ] . push ( [ v , w ] ) ; adj [ v ] . push ( [ u , w ] ) ; } dfs ( R , 0 , K ) ;