#include <bits/stdc++.h>
using namespace std;
ifstream fin("dijkstra.in");
ofstream fout("dijkstra.out");
int n,m,cost[50005];
struct graf
{
int nod,val;
};
vector<graf> v[50005];
struct cmp
{
bool operator() (int a,int b)
{
return cost[a]>cost[b];
}
};
priority_queue<int,vector<int>,cmp> pq;
void dijkstra(int nod)
{
for(int i=1; i<=n; i++)
cost[i]=1e9;
cost[nod]=0;
pq.push(nod);
while(!pq.empty())
{
nod=pq.top();
for(auto x:v[nod])
{
if(cost[x.nod]>cost[nod]+x.val)
{
cost[x.nod]=cost[nod]+x.val;
pq.push(x.nod);
}
}
pq.pop();
}
}
int main()
{
fin>>n>>m;
for(int i=1; i<=m; i++)
{
int a,b,c;
fin>>a>>b>>c;
v[a].push_back({b,c});
}
dijkstra(1);
for(int i=2; i<=n; i++)
fout<<cost[i]<<' ';
return 0;
}