#include #include #include #define MAXN 20 using namespace std; int n, T; int p[MAXN], t[MAXN], d[MAXN]; int dist[MAXN+2][MAXN+2]; int dp[1< (b&1)) return true; if ((a&1) < (b&1)) return false; a >>= 1; b >>= 1; } assert(false); } int main() { cin >> n >> T; for (int i = 0; i < n; ++i) { cin >> p[i] >> t[i] >> d[i]; if (d[i] == -1) d[i] = T+1; } for (int i = 0; i < n+2; ++i) for (int j = 0; j < n+2; ++j) cin >> dist[i][j]; for (int i = 0; i < (1< T) continue; for (int k = 0; k < n; ++k) { if (i&(1< d[k]) continue; dp[i|(1< mx || (val == mx && smaller(i, id))) { id = i; mx = val; hw = ham; } } } if (mx > 0) { cout << mx << endl; for (int j = 0; j < n; ++j) if (id & (1<