#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
ifstream f("dijkstra.in");
ofstream g("dijkstra.out");
auto cmp = [] (pair <int,int> a, pair <int,int> b)
{
return a.second > b.second;
};
priority_queue < pair<int,int>, vector < pair<int,int> >, decltype(cmp)> pq(cmp);
int n,m,x,y,pret,i,a,b,cost[100001];
bitset <100001> trecut;
vector < pair<int,int> > drumuri[100001];
int main()
{
ios::sync_with_stdio(0);
f >> n >> m;
while(m --)
{
f >> x >> y >> pret;
drumuri[x].push_back({y,pret});
}
for(i = 1; i <= n; ++ i)
cost[i] = INF;
for(i = 0; i < drumuri[1].size(); ++ i)
{
cost[drumuri[1][i].first] = drumuri[1][i].second;
pq.push({drumuri[1][i].first,drumuri[1][i].second});
}
cost[1] = 0;
trecut[1] = 1;
while(!pq.empty())
{
a = pq.top().first;
b = pq.top().second;
pq.pop();
if(trecut[a])
continue;
trecut[a] = 1;
for(i = 0; i < drumuri[a].size(); ++ i)
if(!trecut[drumuri[a][i].first] && cost[drumuri[a][i].first] > drumuri[a][i].second + b)
{
cost[drumuri[a][i].first] = drumuri[a][i].second + b;
pq.push({drumuri[a][i].first, drumuri[a][i].second + b});
}
}
for(i = 2 ; i <= n; ++ i)
if(!trecut[i])
g << 0 << ' ';
else
g << cost[i] << ' ';
}