#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1 << 28; //constexpr long long mod = 1000000007LL; constexpr long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; vector dijkstra(ll start, vector>>& graph) { vector dist(graph.size(), INF); dist[start] = 0; priority_queue, vector>, greater>> pq; vector used(dist.size(), false); pq.push(make_pair(0, start)); while (!pq.empty()) { ll d, node; tie(d, node) = pq.top(); pq.pop(); if (used[node]) continue; used[node] = true; for (pair element : graph[node]) { ll new_d, new_node; tie(new_node, new_d) = element; new_d += d; if (new_d < dist[new_node]) { dist[new_node] = new_d; pq.push(make_pair(dist[new_node], new_node)); } } } return dist; } int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ int n, m; scanf("%d %d", &n, &m); vector>> g1(n), g2(n * 2); for (int i = 0; i < m; i++) { ll a, b, c; scanf("%lld %lld %lld", &a, &b, &c); a--; b--; g1[a].emplace_back(b, c); g1[b].emplace_back(a, c); g2[a].emplace_back(b, c); g2[b].emplace_back(a, c); g2[a + n].emplace_back(b + n, c); g2[b + n].emplace_back(a + n, c); g2[a].emplace_back(b + n, 0); g2[b].emplace_back(a + n, 0); } vector d1 = dijkstra(0, g1); vector d2 = dijkstra(0, g2); for (int i = 0; i < n; i++) { cout << d1[i] + min(d2[i + n], d2[i]) << "\n"; } return 0; }