#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x>N>>M; while(M--) { cin>>x>>y>>r; mat[x][y]=r; } ll ma=-1; int cur[51]; int pat[51]; FOR(i,N) cur[i]=i; srand(time(NULL)); FOR(i,800000) { random_shuffle(cur,cur+N); ll tot=0; FOR(y,N) FOR(x,y) tot+=mat[cur[x]][cur[y]]; FOR(j,100) { x=rand()%(N-1); if(mat[cur[x+1]][cur[x]]>mat[cur[x]][cur[x+1]]) { tot -= mat[cur[x]][cur[x+1]]; tot += mat[cur[x+1]][cur[x]]; swap(cur[x],cur[x+1]); if(tot>ma) { ma=tot; FOR(x,N) pat[x]=cur[x]; } } } } _P("%d\n",ma); FOR(i,N) _P("%d%c",pat[i],(i==N-1)?'\n':' '); } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); solve(); return 0; }