Masking previous edges as explained in above formula .
if ( graph [ prev ] [ i ] [ j ] && ! ( mask & ( 1 << i ) ) && ( j != col ) ) { long long z = graph [ prev ] [ i ] [ j ] + minCost ( n , m , mask | ( 1 << i ) , i , j ) ; ans = min ( z , ans ) ; } } } return dp [ mask ] [ prev ] [ col == 1 ] = ans ; }