#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
#define pb push_back
ifstream fin("dijkstra.in");
ofstream fout("dijkstra.out");
const int N = 5e4+3;
const int oo = 0x3f3f3f3f;
int n, d[N];
vector<pii> e[N];
void read(), dijkstra();
int main()
{
fin.tie(0); fout.tie(0);
ios_base::sync_with_stdio(0);
read();
dijkstra();
for (int i = 2; i <= n; i++)
fout << (d[i] == oo ? 0 : d[i]) << ' ';
return 0;
}
void read(){
int m; fin >> n >> m;
while (m--){
int a, b, c; fin >> a >> b >> c;
e[a].pb({b,c});
}
}
void dijkstra(){
memset(d, oo, sizeof d);
set<pii> s; s.insert({0, 1}); d[1] = 0;
while (!s.empty()){
int from, c;
tie(c, from) = *s.begin();
s.erase(s.begin());
for (auto it: e[from]){
int to, ec; tie(to, ec) = it;
if (d[to] > c + ec){
if (d[to] != oo)
s.erase({d[to], to});
d[to] = c + ec;
s.insert({d[to], to});
}
}
}
}
//17:22