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