#include using namespace std; typedef long long ll; #define REP(i, n) for(int(i)=0;(i)<(n);++(i)) #define FOR(i, f, t) for(int(i)=(f);(i)<(t);(++i)) const int MOD = int(1e9+9); int N,M; int k[55],kk[55]; map m[55]; unsigned int xor128(void) { static unsigned int x=123456789,y=362436069,z=521288629,w=88675123; unsigned int t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) ); } int score(){ ll mask = 0; int sc = 0; REP(i,N){ auto &a = m[k[i]]; for(auto it = a.begin(); it != a.end(); ++it){ int b = it->first, c = it->second; if((mask >> b)&1) continue; sc += c; } mask |= 1LL<> N >> M; REP(i,M){ int a,b,c; cin >> a >> b >> c; m[a].insert(make_pair(b,c)); } REP(i,N) k[i] = kk[i] = i; int sc = score(); clock_t t = clock() + CLOCKS_PER_SEC * 4; while(t >= clock()){ int i = xor128() % N; int j = xor128() % N; if(i == j) continue; swap(k[i],k[j]); int s = score(); if(sc < s){ sc = s; REP(i,N) kk[i] = k[i]; } } cout << sc << endl; REP(i,N) cout << kk[i] << " "; return 0; }