Add edges to the vector along with the values of the node
for ( var i = 0 ; i < n ; i ++ ) { g [ u [ i ] ] . push ( [ val [ v [ i ] ] , v [ i ] ] ) ; g [ v [ i ] ] . push ( [ val [ u [ i ] ] , u [ i ] ] ) ; }