#include <bits/stdc++.h>
#define ll long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define INF (ll) 1e18
# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
ll n,m;
ll N=1e5+5;
vector <vector <pair <ll,ll> > >vec(N);
vector <ll> d(N,INF);
struct comp{
bool operator() (const ll &a, const ll &b) const{
return d[a]<d[b];
}
};
int main(){
IOS;
cin>>n>>m;
fr(i,m){
make2(ll,x,y); make(ll,len);
vec[--x].push_back({--y,len});
}
d[0]=0;
set <pair <ll,ll> > q;
q.insert({0,0});
while(!q.empty()){
pair <ll,ll> f=*q.begin(); q.erase(q.begin());
ll e=f.second;
for(auto x : vec[e]){
ll to=x.first; ll len=x.second;
if(d[e]+len<d[to]){
q.erase({d[to],to});
d[to]=d[e]+len;
q.insert({d[to],to});
}
}
}
fr(i,n) cout<<d[i]<<" ";
cout<<endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgbWFrZSh0eXBlLHgpIHR5cGUgeDsgY2luPj54CiNkZWZpbmUgbWFrZTIodHlwZSx4LHkpIHR5cGUgeCx5OyBjaW4+Png+PnkKI2RlZmluZSBmcih4LHkpIGZvcihsb25nIGxvbmcgeD0wO3g8eTt4KyspCiNkZWZpbmUgSU5GIChsbCkgMWUxOAogCiMgZGVmaW5lIElPUyBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsgY2luLnRpZShOVUxMKQogCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAKbGwgbixtOwpsbCBOPTFlNSs1Owp2ZWN0b3IgPHZlY3RvciA8cGFpciA8bGwsbGw+ID4gPnZlYyhOKTsKdmVjdG9yIDxsbD4gZChOLElORik7CnN0cnVjdCBjb21wewogICAgYm9vbCBvcGVyYXRvcigpIChjb25zdCBsbCAmYSwgY29uc3QgbGwgJmIpIGNvbnN0ewogICAgICAgIHJldHVybiBkW2FdPGRbYl07CiAgICB9CiAKfTsKaW50IG1haW4oKXsKICAgIElPUzsKICAgIGNpbj4+bj4+bTsKICAgIGZyKGksbSl7CiAgICAgICAgbWFrZTIobGwseCx5KTsgbWFrZShsbCxsZW4pOwogICAgICAgIHZlY1stLXhdLnB1c2hfYmFjayh7LS15LGxlbn0pOwogICAgfQogICAgZFswXT0wOwogICAgc2V0IDxwYWlyIDxsbCxsbD4gPiBxOwogICAgcS5pbnNlcnQoezAsMH0pOwogICAgd2hpbGUoIXEuZW1wdHkoKSl7CiAgICAgICAgcGFpciA8bGwsbGw+IGY9KnEuYmVnaW4oKTsgcS5lcmFzZShxLmJlZ2luKCkpOwogICAgICAgIGxsIGU9Zi5zZWNvbmQ7CiAgICAgICAgZm9yKGF1dG8geCA6IHZlY1tlXSl7CiAgICAgICAgICAgIGxsIHRvPXguZmlyc3Q7IGxsIGxlbj14LnNlY29uZDsKICAgICAgICAgICAgaWYoZFtlXStsZW48ZFt0b10pewogICAgICAgICAgICAgICAgcS5lcmFzZSh7ZFt0b10sdG99KTsKICAgICAgICAgICAgICAgIGRbdG9dPWRbZV0rbGVuOwogICAgICAgICAgICAgICAgcS5pbnNlcnQoe2RbdG9dLHRvfSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICBmcihpLG4pIGNvdXQ8PGRbaV08PCIgIjsKICAgIGNvdXQ8PGVuZGw7CiAgICByZXR1cm4gMDsKfQ==