Mad scientist Mike has applied for a job. His task is to manage a system of water pumping stations.

The system consists of n pumping stations, which are numbered by integers from 1 to n. Some pairs of stations are connected by bidirectional pipes through which water can flow in either direction (but only in one at a time). For each pipe you know its bandwidth — the maximum number of liters of water that can flow through it in one hour. Each pumping station can pump incoming water from some stations to other stations through the pipes, provided that in one hour the total influx of water to the station is equal to the total outflux of water from the station.

It is Mike's responsibility to pump water between stations. From station a to station b through the pipes (possibly through other stations) within one hour one can transmit a certain number of liters of water according to the rules described above. During this time, water from other stations can not flow into station a, and can not flow out of the station b. However, any amount of water can flow out of station a or in station b. If a total of x litres of water flows out of the station a in an hour, then Mike gets x bollars more to his salary.

To get paid, Mike needs to work for n - 1 days, according to the contract. On the first day he selects two stations v1 and v2, and within one hour he pumps a certain amount of water from v1 to v2. Next, on the i-th day Mike chooses a station vi + 1 that has been never selected before, and pumps a certain amount of water out of the station vi to station vi + 1 for one hour. The quantity of water he pumps on the i-th day does not depend on the amount of water pumped on the (i - 1)-th day.

Mike needs to earn as much bollars as he can for his projects. Help Mike find such a permutation of station numbers v1, v2, ..., vn so Mike will be able to earn the highest possible salary.

 

Input

The first line of the input contains two space-separated integers n and m (2 ≤ n ≤ 200, 1 ≤ m ≤ 1000) — the number of stations and pipes in the system, accordingly. The i-th of the next m lines contains three space-separated integers aibi and ci (1 ≤ ai, bi ≤ nai ≠ bi, 1 ≤ ci ≤ 100) — the numbers of stations connected by the i-th pipe and the pipe's bandwidth, accordingly. It is guaranteed that any two stations are connected by at most one pipe and that there is a pipe path between any two stations.

Output

On the first line print a single integer — the maximum salary Mike can earn.

On the second line print a space-separated permutation of n numbers from 1 to n — the numbers of stations in the sequence v1, v2, ..., vn. If there are multiple answers, print any of them.

 

Examples

Input

6 11
1 2 10
1 6 8
2 3 4
2 5 2
2 6 3
3 4 5
3 5 4
3 6 2
4 5 7
4 6 2
5 6 3

Output

77
6 2 1 5 3 4 

 

 

 

 

 

 

题解

乍一看感觉十分不好下手,先建棵最小割树压压惊

由于最小割树的性质,两点的最小割是它们在最小割树上的路径最小边权

于是我们贪心的想一下

对于一个权值较小的边,我们应该让它的有效经过次数(就是由它来决定答案的次数)尽量的少,最好是1次

然后我们就可以把整棵树按边权最小的边分为两块,发现我们只要不在两个连通块中交叉选点,即可保证最小边只经过一次。

进而发现这个问题可以递归地做下去,最后就可以得到答案序列

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 1005
#define M 200005
const int INF=0x3f3f3f3f;
int n,m;
int fir[N],to[M],nxt[M],cap[M],cnt;
void adde(int a,int b,int c1,int c2)
{
	to[++cnt]=b;nxt[cnt]=fir[a];fir[a]=cnt;cap[cnt]=c1;
	to[++cnt]=a;nxt[cnt]=fir[b];fir[b]=cnt;cap[cnt]=c2;
}
int S,T,flow,d[N],vd[N];
int sap(int u,int aug)
{
	if(u==T) return aug;
	int tmp,ret=0,mind=n-1;
	for(int v,p=fir[u];p;p=nxt[p]){
		v=to[p];
		if(cap[p]>0){
			if(d[u]==d[v]+1){
				tmp=sap(v,min(cap[p],aug));
				aug-=tmp;cap[p]-=tmp;
				ret+=tmp;cap[p^1]+=tmp;
				if(d[S]>=T) return ret;
				if(aug==0) break;
			}
			mind=min(mind,d[v]);
		}
	}
	if(ret==0){
		vd[d[u]]--;
		if(!vd[d[u]])
			d[S]=T;
		d[u]=mind+1;
		vd[d[u]]++;
	}
	return ret;
}
void f()
{
	memset(d,0,sizeof(d));
	memset(vd,0,sizeof(vd));
	vd[0]=n;flow=0;
	while(d[S]<n)
		flow+=sap(S,INF);
}
struct node{
	int u,v,c;
}e[M];
void rebuild(int s,int t)
{
	memset(fir,0,sizeof(fir));cnt=1;
	for(int i=1;i<=m;i++)
		adde(e[i].u,e[i].v,e[i].c,e[i].c);
	S=s;T=t;
}
bool vs[N];
void dfs(int u)
{
	vs[u]=1;
	for(int v,p=fir[u];p;p=nxt[p]){
		v=to[p];
		if(cap[p]>0&&!vs[v])
			dfs(v);
	}
}
int fa[N],val[N],sum;
void build()
{
	for(int i=1;i<=n;i++)fa[i]=1;
	for(int u=2,v;u<=n;u++){
		v=fa[u];
		rebuild(u,v);f();
		memset(vs,0,sizeof(vs));dfs(S);
		for(int i=1;i<=n;i++)
			if(i!=u&&fa[i]==v&&vs[i])
				fa[i]=u;
		if(vs[fa[v]]){
			fa[u]=fa[v];val[u]=val[v];
			fa[v]=u;val[v]=flow;
		}
		else{fa[u]=v;val[u]=flow;}
	}
	memset(fir,0,sizeof(fir));cnt=1;sum=0;
	for(int i=2;i<=n;i++){
		adde(i,fa[i],val[i],val[i]);
		sum+=val[i];
	}
}
bool vis[N];int mi,pos;
int dfs1(int u,int ff)
{
	int ret=1;
	for(int v,p=fir[u];p;p=nxt[p]){
		v=to[p];
		if(!vis[p]&&v!=ff){
			if(cap[p]<mi){
				mi=cap[p];
				pos=p;
			}
			ret+=dfs1(v,u);
		}
	}
	return ret;
}
int ans[N],acnt;
void solve(int u)
{
	mi=INF;pos=0;
	if(dfs1(u,0)==1){
		ans[++acnt]=u;
		return;
	}
	vis[pos]=vis[pos^1]=1;
	int tmp=pos;
	solve(to[tmp]);
	solve(to[tmp^1]);
}
int main()
{
	int i;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++)
		scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].c);
	build();
	printf("%d\n",sum);
	solve(1);
	printf("%d",ans[1]);
	for(i=2;i<=n;i++)
		printf(" %d",ans[i]);
}//cqbzcsq