#include #define INF 2147483647 #define INF_LL 9223372036854775807 #define MOD 1000000007 using namespace std; typedef long long int ll; typedef unsigned long long int ull; vector > mat; int N, M; int main() { cin >> N >> M; mat = vector >(N, vector(N, -1)); for (int i = 0; i < M; i++) { int a, b, c; cin >> a >> b >> c; a--; b--; mat[a][b] = mat[b][a] = c; } int ans = -1; vector > dp((1 << N), vector(N, -1)); //dp[S][i] 集合Sに訪れていて駅iにいる for (int i = 0; i < N; i++)dp[1 << i][i] = 0; for (int i = 0; i < (1 << N); i++) { for (int j = 0; j < N; j++) { if (dp[i][j] == -1)continue; bool flag = false; for (int k = 0; k < N; k++) { if (i & (1 << k) || mat[j][k] == -1)continue; flag = true; dp[i + (1 << k)][k] = max(dp[i + (1 << k)][k], dp[i][j] + mat[j][k]); } if (!flag)ans = max(dp[i][j], ans); } } cout << ans << endl; }