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