#include using namespace std; const size_t MAX_N = 9; int N, M; int score[MAX_N][MAX_N]; int calc(const vector& v) { int res = 0; for (size_t i = 0; i < N; i++) { for (size_t j = i + 1; j < N; j++) { res += score[v[i]][v[j]]; } } return res; } void solve() { vector v; for (size_t i = 0; i < N; i++) { v.push_back(i); } int ans = numeric_limits::min(); do { ans = max(ans, calc(v)); } while (next_permutation(v.begin(), v.end())); cout << ans << endl; } int main() { cin >> N >> M; for (size_t i = 0; i < M; i++) { int item1, item2; cin >> item1 >> item2; cin >> score[item1][item2]; } solve(); }