#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int,int> PII;
const int NMAX = 50000+5;
const int INF = (1LL<<31)-1;
void Read(),Dijkstra(),Print();
int N,M;
int Dist[NMAX];
vector<PII> V[NMAX];
priority_queue<PII,vector<PII>,greater<PII> > PQ;
int main()
{
Read();
Dijkstra();
Print();
return 0;
}
void Read()
{
int x,y,c;
freopen("dijkstra.in","r",stdin);
freopen("dijkstra.out","w",stdout);
scanf("%d%d",&N,&M);
for(; M; --M)
{
scanf("%d%d%d",&x,&y,&c);
V[x].push_back(make_pair(y,c));
V[y].push_back(make_pair(x,c));
}
}
void Dijkstra()
{
int i,x;
vector<PII>::iterator it;
for(i = 2; i <= N; i++)
Dist[i] = INF;
PQ.push(make_pair(0,1));
while(!PQ.empty())
{
x = PQ.top().second;
PQ.pop();
for(it = V[x].begin(); it != V[x].end(); it++)
if(Dist[x] + it->second < Dist[it->first])
{
Dist[it->first] = Dist[x] + it->second;
PQ.push(make_pair(Dist[it->first],it->first));
}
}
}
void Print()
{
int i;
for(i = 2; i <= N; i++)
printf("%d ",Dist[i]==INF?0:Dist[i]);
}