#include <iostream>
#include <fstream>
#include <queue>
#include <vector>
using namespace std;
ifstream fin("dijkstra.in");
ofstream fout("dijkstra.out");
const int INF=1e9;
int n,m;
priority_queue<pair<int,int>> pq;
int d[50001], vis[50001];
vector<vector<pair<int,int>>> g(20001);
void dijkstra(int s) {
for(int i=1;i<=n;i++) {
d[i]=INF;
}
d[s]=0;
pq.push({-d[s],s});
while(!pq.empty()) {
int x=pq.top().second;
pq.pop();
if(vis[x]==0) {
vis[x]=1;
for(auto& it:g[x]) {
int vec=it.first;
int cost=it.second;
if(d[vec]>d[x]+cost) {
d[vec]=d[x]+cost;
pq.push({-d[vec],vec});
}
}
}
}
}
int main() {
fin>>n>>m;
for(int i=0;i<m;i++) {
int a,b,c;
fin>>a>>b>>c;
g[a].push_back({b,c});
}
dijkstra(1);
for (int i=2;i<=n;i++) {
if (d[i]==INF) {
fout<<0<<" ";
} else {
fout<<d[i]<<" ";
}
}
}