#include <bits/stdc++.h>
using namespace std;
ifstream in("cmlsc.in");
ofstream out("cmlsc.out");
int main() {
int n, m;
in >> n >> m;
std::vector<std::vector<std::pair<int, int>>> adj(n, std::vector<std::pair<int, int>>());
for (int i = 0; i < m; i++) {
int x, y, c;
in >> x >> y >> c;
x--;
y--;
adj[x].push_back({c, y});
}
std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>, std::greater<std::pair<int, int>>> q;
std::vector<int> dp(n, 1e9);
std::vector<bool> ok(n, false);
dp[0] = 0;
q.push({0, 0});
while (!q.empty()) {
auto [cost, node] = q.top();
q.pop();
if (ok[node])
continue;
ok[node] = true;
for (auto it : adj[node]) {
if (dp[it.second] > cost + it.first) {
dp[it.second]= cost + it.first;
q.push({dp[it.second], it.second});
}
}
}
for (int i = 1; i < n; i++)
out << dp[i] << " ";
}