#include #include #include using namespace std; int main() { int n, m; cin >> n >> m; vector item1(m), item2(m), score(m); for (int i = 0; i < m; ++i) { cin >> item1[i] >> item2[i] >> score[i]; } int maxScore = 0; vector positions(n); for (int i = 0; i < n; ++i) { positions[i] = i; } do { int s = 0; for (int k = 0; k < m; ++k) { if (positions[item1[k]] < positions[item2[k]]) { s += score[k]; } } maxScore = max(maxScore, s); } while (next_permutation(&positions[0], &positions[n - 1] + 1)); cout << maxScore << endl; return 0; }