#include <fstream>
#include <queue>
#include <vector>
#include <climits>
using namespace std;
ifstream fin("dijkstra.in");
ofstream fout("dijkstra.out");
vector<pair<int, int> > G[50001];
int cost[50001];
void dijkstra(){
priority_queue<pair<int, int>, vector<pair<int,int> >, greater<pair<int,int> > > pq;
pq.push(make_pair(0,1));
while(!pq.empty()){
pair<int,int> nod = pq.top();
pq.pop();
if(nod.first != cost[nod.second]){
continue;
}
for (int i = 0; i < G[nod.second].size(); i ++){
pair<int, int> nod_nou = make_pair(cost[nod.second] + G[nod.second][i].second, G[nod.second][i].first);
if(nod_nou.first < cost[nod_nou.second]){
pq.push(nod_nou);
cost[nod_nou.second] = nod_nou.first;
}
}
}
}
int main (){
int n, m;
fin >> n >> m;
while(m--){
int lg_arc, A, B;
fin >> A >> B >> lg_arc;
G[A].push_back(make_pair(B,lg_arc));
}
for (int i = 2; i <= n; i ++){
cost[i] = INT_MAX;
}
dijkstra();
for (int i = 2; i <= n; i ++){
if(cost[i] == INT_MAX){
cost[i] = 0;
}
fout << cost[i] << " ";
}
}