#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; void main_(); signed main() { cin.tie(0); ios::sync_with_stdio(false); main_(); return 0; } #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) #define all(c) (c).begin(), (c).end() #define zero(a) memset(a, 0, sizeof a) #define minus(a) memset(a, -1, sizeof a) template inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); } template inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); } typedef long long ll; int const inf = 1<<29; int N, M; vector> g[15]; int dp[1<<15]; int dfs(int bit) { if(bit == (1 << N)-1) { return 0; } int& ret = dp[bit]; if(ret + 1) { return ret; } ret = 0; rep(i, N) { if(!(bit >> i) & 1) { continue; } rep(j, N) { if(bit >> j & 1) { continue; } // jを新しく使う auto iter = lower_bound(all(g[i]), make_pair(j, -inf)); if(iter != g[i].end()) { maximize(ret, dfs(bit | (1<second); } } } return ret; } void main_() { cin >> N >> M; rep(i, M) { int i1, i2, s; cin >> i1 >> i2 >> s; g[i2].emplace_back(i1, s); } rep(i, 15) { sort(all(g[i])); } int res = 0; rep(i, N) { minus(dp); maximize(res, dfs(1<