#include #include #include using namespace std; typedef long long ll; int main() { int n, m, s, tmp; cin >> n >> m; vector > e(n, vector(n, 0)); for(int i = 0; i < m; i++) { int from, to, cost; cin >> from >> to >> cost; e[from][to] = cost; } s = 1 << n; int dp[1 << 14] = {}; for(int i = 1; i < s; i++) { for(int j = 0; j < n; j++) { if ((1 << j) & i) continue; tmp = 0; for(int k = 0; k < n; k++) { if ((1 << k) & i) { tmp += e[k][j]; } } dp[i | (1 << j)] = max(dp[i | (1 << j)], dp[i] + tmp); } } cout << dp[s - 1] << "\n"; return 0; }