#include using namespace std; #define int long long templatebool chmax(T &a, const T &b) { if (a> N >> M; for (int i = 0; i < M; i++) { cin >> item1[i] >> item2[i] >> score[i]; } // 並び方を定義する配列 vector v(N); iota(v.begin(), v.end(), 0); int ans = 0; do { int sum = 0; // この並びの時の合計スコア // その並びになってるかを全て調べる for (int i = 0; i < M; i++) { int cnt = 0; for (int j = 0; j < N; j++) { if (cnt == 0 and v[j] == item1[i]) { cnt++; } if (cnt == 1 and v[j] == item2[i]) { cnt++; } } // その並びになってたらスコアを足す if (cnt == 2) { sum += score[i]; } } chmax(ans, sum); } while (next_permutation(v.begin(), v.end())); cout << ans << endl; return 0; }