#include<bits/stdc++.h>
using namespace std;
struct tip
{
int nod;
long long cost;
bool operator<(const tip& other) const
{
return cost>other.cost;
}
};
const int maxN=(5e4)+5;
const long long inf=10000000000LL;
priority_queue<tip> q;
long long dp[maxN];
vector<pair<int,int> > v[maxN];
inline void dijkstra()
{
while(!q.empty())
{
int nod=q.top().nod;
long long cost=q.top().cost;
q.pop();
if(cost>dp[nod]) continue;
for(auto it:v[nod])
{
long long z=cost+1LL*it.second;
if(z<dp[it.first])
{
dp[it.first]=z;
q.push({it.first,dp[it.first]});
}
}
}
}
int n,m,x,y,z;
int main()
{
freopen("dijkstra.in","r",stdin);
freopen("dijkstra.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&x,&y,&z);
v[x].push_back({y,z});
}
for(int i=2;i<=n;i++)
dp[i]=inf;
q.push({1,0LL});
dijkstra();
for(int i=2;i<=n;i++)
printf("%lld ",dp[i]);
printf("\n");
return 0;
}