#include <bits/stdc++.h>
using namespace std;
ifstream fin("dijkstra.in");
ofstream fout("dijkstra.out");
const int NMAX=5e4+8;
int n,m;
vector<pair<int,int> > g[NMAX];
int dist[NMAX];
void dijk(int src, int dist[]) {
for(int i=1; i<=n; i++) {
dist[i]=INT_MAX;
}
dist[src]=0;
priority_queue<pair<int,int>, vector<pair<int,int> >,
greater<pair<int,int> > > pq; pq.push({0,1});
while(!pq.empty()) {
int nod=pq.top().second;
pq.pop();
for(const auto &[vec,w]:g[nod]) {
if(dist[vec]>w+dist[nod]) {
dist[vec]=w+dist[nod];
pq.push({dist[vec],vec});
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
fin.tie(nullptr);
fout.tie(nullptr);
fin >> n >> m;
for(int i=1; i<=m; i++) {
int x,y,w;
fin >> x >> y >> w;
g[x].push_back({y,w});
}
dijk(1,dist);
for(int i=2; i<=n; i++) {
fout << (dist[i]==INT_MAX ? 0 : dist[i]) << " ";
}
fout << "\n";
return 0;
}