#include using namespace std; int N, M; vector> adj[20]; // adj[i] = {企業, 契約価値} map, long long> memo; // 状態: (Alice のグループのビットマスク, Bob のグループのビットマスク, 現在のターン) // ターン: 0 = Alice, 1 = Bob long long dfs(long long alice_mask, long long bob_mask, int turn) { long long used_mask = alice_mask | bob_mask; // すべての企業が買収されたら終了 if (used_mask == (1LL << N) - 1) { return 0; } // メモ化キー pair state = {used_mask, turn}; if (memo.count(state)) { return memo[state]; } long long result; if (turn == 0) { // Alice のターン(最大化) result = LLONG_MIN; // 未買収の企業を列挙 for (int i = 0; i < N; i++) { if (!(used_mask & (1LL << i))) { // 企業 i を Alice のグループに加える long long gain = 0; for (auto [j, cost] : adj[i]) { if (alice_mask & (1LL << j)) { gain += cost; } } long long next_score = gain + dfs(alice_mask | (1LL << i), bob_mask, 1); result = max(result, next_score); } } } else { // Bob のターン(最小化) result = LLONG_MAX; // 未買収の企業を列挙 for (int i = 0; i < N; i++) { if (!(used_mask & (1LL << i))) { // 企業 i を Bob のグループに加える long long gain = 0; for (auto [j, cost] : adj[i]) { if (bob_mask & (1LL << j)) { gain += cost; } } long long next_score = dfs(alice_mask, bob_mask | (1LL << i), 0) - gain; result = min(result, next_score); } } } return memo[state] = result; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> M; for (int i = 0; i < M; i++) { int u, v; long long w; cin >> u >> v >> w; u--; v--; // 0-indexed adj[u].push_back({v, w}); adj[v].push_back({u, w}); } long long ans = dfs(0, 0, 0); cout << ans << endl; return 0; }