#include #include #include #include using namespace std; const int MAX_N = 14, MAX_M = MAX_N * (MAX_N - 1); int G[MAX_N][MAX_N]; void add_edge(int from, int to, int cost) { G[from][to] = cost; } int N, M; int item1[MAX_M], item2[MAX_M], score[MAX_M]; int dp[1 << MAX_N]; void solve() { sizeof(G, 0, sizeof(G)); sizeof(dp, -1, sizeof(dp)); for (int i = 0; i < M; i++) { add_edge(item1[i], item2[i], score[i]); } for (int S = 0; S < 1 << N; S++) { for (int t = 0; t < N; t++) { if (!(S >> t & 1)) { int s = 0; for (int f = 0; f < N; f++) { if (S >> f & 1) { s += G[f][t]; } } dp[S | 1 << t] = max(dp[S | 1 << t], dp[S] + s); } } } printf("%d\n", dp[(1 << N) - 1]); } int main() { scanf("%d %d", &N, &M); for (int i = 0; i < M; i++) { scanf("%d %d %d", &item1[i], &item2[i], &score[i]); } solve(); }