Update the minimum value such than it should be greater than 0
if ( minVal [ a ] >= 0 && minVal [ b ] >= 0 ) { minVal [ a ] = min ( minVal [ a ] , minVal [ b ] ) ; } else if ( minVal [ a ] >= 0 && minVal [ b ] < 0 ) { minVal [ a ] = minVal [ a ] ; } else if ( minVal [ a ] < 0 && minVal [ b ] >= 0 ) { minVal [ a ] = minVal [ b ] ; } else { minVal [ a ] = max ( minVal [ a ] , minVal [ b ] ) ; } } else { parent [ a ] = b ;