Adding the contribution of leaves outside to the ith node
dp [ v [ a ] [ i ] . first ] += ( dp [ a ] - dp [ v [ a ] [ i ] . first ] ) ; dp [ v [ a ] [ i ] . first ] += v [ a ] [ i ] . second * ( leafOutside - leaves [ v [ a ] [ i ] . first ] ) ;