#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int maxN = 1e6+12;
const int MOD = 1e9+7;
const ll inf = 1e18;
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
int n, m;
ll d[maxN];
bool mark[maxN];
vector<pair<ll,ll>> g[maxN];
void dijkstra(int s)
{
d[s]=0;
priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> pq;
pq.push({0,s});
while(!pq.empty()){
ll u = pq.top().second;
pq.pop();
if(!mark[u]){
mark[u]=1;
for(auto v: g[u]){
ll x = v.first;
ll y = v.second;
if(d[x] > d[u]+y){
d[x] = d[u]+y;
pq.push({d[x],x});
}
}
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen("a.inp", "r")){
freopen("a.inp", "r", stdin);
freopen("a.out", "w", stdout);
}
cin >> n >> m;
for(int i=1; i<=m; i++){
int a, b, c;
cin >> a >> b >> c;
g[a].push_back({b,c});
}
fill_n(mark, n+1, 0);
fill_n(d, n+1, inf);
dijkstra(1);
for(int i=1; i<=n; i++) cout << d[i] << " ";
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiAKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIAojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIGVuZGwgJ1xuJwogCmNvbnN0IGludCBtYXhOID0gMWU2KzEyOwpjb25zdCBpbnQgTU9EID0gMWU5Kzc7CmNvbnN0IGxsIGluZiA9IDFlMTg7CiAKdGVtcGxhdGU8dHlwZW5hbWUgVD4gYm9vbCBtYXhpbWl6ZShUICZyZXMsIGNvbnN0IFQgJnZhbCkgeyBpZiAocmVzIDwgdmFsKXsgcmVzID0gdmFsOyByZXR1cm4gdHJ1ZTsgfTsgcmV0dXJuIGZhbHNlOyB9CnRlbXBsYXRlPHR5cGVuYW1lIFQ+IGJvb2wgbWluaW1pemUoVCAmcmVzLCBjb25zdCBUICZ2YWwpIHsgaWYgKHJlcyA+IHZhbCl7IHJlcyA9IHZhbDsgcmV0dXJuIHRydWU7IH07IHJldHVybiBmYWxzZTsgfQogCmludCBuLCBtOwpsbCBkW21heE5dOwpib29sIG1hcmtbbWF4Tl07CnZlY3RvcjxwYWlyPGxsLGxsPj4gZ1ttYXhOXTsKIAp2b2lkIGRpamtzdHJhKGludCBzKQp7CiAgICBkW3NdPTA7CiAgICBwcmlvcml0eV9xdWV1ZTxwYWlyPGxsLGxsPiwgdmVjdG9yPHBhaXI8bGwsbGw+PiwgZ3JlYXRlcjxwYWlyPGxsLGxsPj4+IHBxOwogCiAgICBwcS5wdXNoKHswLHN9KTsKIAogICAgd2hpbGUoIXBxLmVtcHR5KCkpewogICAgICAgIGxsIHUgPSBwcS50b3AoKS5zZWNvbmQ7CiAgICAgICAgcHEucG9wKCk7CiAKICAgICAgICBpZighbWFya1t1XSl7CiAgICAgICAgICAgIG1hcmtbdV09MTsKICAgICAgICAgICAgZm9yKGF1dG8gdjogZ1t1XSl7CiAgICAgICAgICAgICAgICBsbCB4ID0gdi5maXJzdDsKICAgICAgICAgICAgICAgIGxsIHkgPSB2LnNlY29uZDsKIAogICAgICAgICAgICAgICAgaWYoZFt4XSA+IGRbdV0reSl7CiAgICAgICAgICAgICAgICAgICAgZFt4XSA9IGRbdV0reTsKICAgICAgICAgICAgICAgICAgICBwcS5wdXNoKHtkW3hdLHh9KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KfQogCmludCBtYWluKCkKewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsKICAgIGNpbi50aWUoMCk7CiAgICBjb3V0LnRpZSgwKTsKIAogICAgaWYoZm9wZW4oImEuaW5wIiwgInIiKSl7CiAgICAgICAgZnJlb3BlbigiYS5pbnAiLCAiciIsIHN0ZGluKTsKICAgICAgICBmcmVvcGVuKCJhLm91dCIsICJ3Iiwgc3Rkb3V0KTsKICAgIH0KIAogICAgY2luID4+IG4gPj4gbTsKICAgIGZvcihpbnQgaT0xOyBpPD1tOyBpKyspewogICAgICAgIGludCBhLCBiLCBjOwogICAgICAgIGNpbiA+PiBhID4+IGIgPj4gYzsKICAgICAgICBnW2FdLnB1c2hfYmFjayh7YixjfSk7CiAgICB9CiAKICAgIGZpbGxfbihtYXJrLCBuKzEsIDApOwogICAgZmlsbF9uKGQsIG4rMSwgaW5mKTsKIAogICAgZGlqa3N0cmEoMSk7CiAKICAgIGZvcihpbnQgaT0xOyBpPD1uOyBpKyspIGNvdXQgPDwgZFtpXSA8PCAiICI7CiAKICAgIHJldHVybiAwOwp9Cg==