Masking previous edges as explained in above formula .
if graph [ prev ] [ i ] [ j ] and not ( mask & ( 1 << i ) ) and ( j != col ) : NEW_LINE INDENT z = graph [ prev ] [ i ] [ j ] + minCost ( n , m , mask | ( 1 << i ) , i , j ) NEW_LINE ans = min ( z , ans ) NEW_LINE DEDENT dp [ mask ] [ prev ] [ col == 1 ] = ans NEW_LINE return dp [ mask ] [ prev ] [ col == 1 ] NEW_LINE