#include "bits/stdc++.h" using namespace std; int main() { int N, M; cin >> N >> M; vector item1(M), item2(M), score(M); vector> point(N, vector(N, 0)); for (int i = 0; i < M; i++) { cin >> item1[i] >> item2[i] >> score[i]; point[item1[i]][item2[i]] += score[i]; } int ans = -1; vector ans2(M); for (int t = 0; t < 2000; t++) { vector temp; int tempscore = 0; for (int i = 0; i < N; i++) { temp.push_back(i); } for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { tempscore += point[i][j]; } } for (int i = 0; i < 2000; i++) { int ta = rand() % N; int tb = rand() % N; if (ta > tb) swap(ta, tb); if (ta == tb) continue; int a = temp[ta]; int b = temp[tb]; //swap(temp[ta], temp[tb]); int add = 0; for (int j = ta + 1; j < tb; j++) { add -= point[a][temp[j]]; add += point[temp[j]][a]; add += point[b][temp[j]]; add -= point[temp[j]][b]; } add -= point[a][b]; add += point[b][a]; if (add>0){ swap(temp[ta], temp[tb]); tempscore += add; } } if (ans < tempscore){ ans = tempscore; ans2 = temp; } } cout << ans << endl; for (int i = 0; i < N; i++) { cout << ans2[i] << endl; } cin >> N; }