#include #include #include typedef std::int_fast32_t s32; typedef std::uint_fast32_t u32; typedef std::int_fast64_t s64; typedef std::uint_fast64_t u64; const unsigned long mod = 1000000007; const double EPS = 0.00000001; const int INF = (1 << 29); typedef std::pair P; template void print_array(T *A_, s32 size) { printf("%d\n", size); if( size != 0 ) { for(int i = 0; i < size - 1; ++i) { printf("%d ", A_[i]); } printf("%d\n", A_[size - 1]); } } template inline std::istream& operator >> (std::istream& is, std::complex& C) { T R, I; std::cin >> R >> I; C = std::complex(R, I); return is; } int A[10]; int n, m; int score[16][16]; int calc(void) { int res = 0; for(int i = 0; i < n; ++i) { for(int j = i + 1; j < n; ++j) { res += score[A[i]][A[j]]; } } return res; } void rand_swap(void) { std::swap(A[rand() % n], A[rand() % n]); } int main() { std::cin >> n >> m; for(int i = 0; i < m; ++i) { int a, b, s; std::cin >> a >> b >> s; score[a][b] = s; } for(int i = 0; i < n; ++i) { A[i] = i; } int res = -1; int times = 100; int temp; srand(time(NULL)); for(int i = 0; i < times; ++i) { int res2 = -1; for(int j = 0; j < 8; ++j) { rand_swap(); } for(int p = 0; p < n; ++p) { for(int q = p + 1; q < n; ++q) { std::swap(A[p], A[q]); temp = calc(); std::swap(A[p], A[q]); if( res2 < temp ) { res2 = temp; } } } res = std::max(res, res2); } std::cout << res << std::endl; return 0; }