#include <bits/stdc++.h>
#define inf 1e9
using namespace std;
ifstream fin("dijkstra.in");
ofstream fout("dijkstra.out");
vector < pair <int, int> > G[50005];
set < pair <int, int> > s;
int d[50005];
bool viz[50005];
void dijkstra(){
d[1] = 0;
s.insert({0,1});
while(!s.empty()){
set < pair <int, int> > :: iterator it = s.begin();
int nod = it->second;
s.erase(it);
if(viz[nod]) continue;
viz[nod] = 1;
for(int i = 0; i < G[nod].size(); ++i){
int c = G[nod][i].first;
int x = G[nod][i].second;
if(!viz[x] && d[nod] + c < d[x]){
d[x] = d[nod] + c;
s.insert({d[x],x});
}
}
}
}
int main()
{
int n,m,i,u,v,c;
cin >> n >> m;
for(i = 1; i <= n; i++) d[i] = inf;
for(i = 1; i <= m; i++){
cin >> u >> v >> c;
G[u].push_back({c,v});
}
dijkstra();
for(i = 2; i <= n; i++) cout << (d[i] != inf ? d[i] : 0) << " ";
cout << "\n";
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgaW5mIDFlOQp1c2luZyBuYW1lc3BhY2Ugc3RkOwppZnN0cmVhbSBmaW4oImRpamtzdHJhLmluIik7Cm9mc3RyZWFtIGZvdXQoImRpamtzdHJhLm91dCIpOwp2ZWN0b3IgPCBwYWlyIDxpbnQsIGludD4gPiBHWzUwMDA1XTsKc2V0IDwgcGFpciA8aW50LCBpbnQ+ID4gczsKaW50IGRbNTAwMDVdOwpib29sIHZpels1MDAwNV07CnZvaWQgZGlqa3N0cmEoKXsKICAgIGRbMV0gPSAwOwogICAgcy5pbnNlcnQoezAsMX0pOwogICAgd2hpbGUoIXMuZW1wdHkoKSl7CiAgICAgICAgc2V0IDwgcGFpciA8aW50LCBpbnQ+ID4gOjogaXRlcmF0b3IgaXQgPSBzLmJlZ2luKCk7CiAgICAgICAgaW50IG5vZCA9IGl0LT5zZWNvbmQ7CiAgICAgICAgcy5lcmFzZShpdCk7CiAgICAgICAgaWYodml6W25vZF0pIGNvbnRpbnVlOwogICAgICAgIHZpeltub2RdID0gMTsKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgR1tub2RdLnNpemUoKTsgKytpKXsKICAgICAgICAgICAgaW50IGMgPSBHW25vZF1baV0uZmlyc3Q7CiAgICAgICAgICAgIGludCB4ID0gR1tub2RdW2ldLnNlY29uZDsKICAgICAgICAgICAgaWYoIXZpelt4XSAmJiBkW25vZF0gKyBjIDwgZFt4XSl7CiAgICAgICAgICAgICAgICBkW3hdID0gZFtub2RdICsgYzsKICAgICAgICAgICAgICAgIHMuaW5zZXJ0KHtkW3hdLHh9KTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KfQppbnQgbWFpbigpCnsKICAgIGludCBuLG0saSx1LHYsYzsKICAgIGNpbiA+PiBuID4+IG07CiAgICBmb3IoaSA9IDE7IGkgPD0gbjsgaSsrKSBkW2ldID0gaW5mOwogICAgZm9yKGkgPSAxOyBpIDw9IG07IGkrKyl7CiAgICAgICAgY2luID4+IHUgPj4gdiA+PiBjOwogICAgICAgIEdbdV0ucHVzaF9iYWNrKHtjLHZ9KTsKICAgIH0KICAgIGRpamtzdHJhKCk7CiAgICBmb3IoaSA9IDI7IGkgPD0gbjsgaSsrKSBjb3V0IDw8IChkW2ldICE9IGluZiA/IGRbaV0gOiAwKSA8PCAiICI7CiAgICBjb3V0IDw8ICJcbiI7CiAgICByZXR1cm4gMDsKfQ==