#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; void dijkstra(ll start, vector> graph[], vector& dist) { 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)); } } } } vector> g[100000]; vector> eg[200000]; int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < m; i++) { ll a, b, c; scanf("%lld %lld %lld", &a, &b, &c); a--; b--; g[a].emplace_back(b, c); g[b].emplace_back(a, c); eg[a].emplace_back(b, c); eg[b].emplace_back(a, c); eg[a + n].emplace_back(b + n, c); eg[b + n].emplace_back(a + n, c); eg[a].emplace_back(b + n, 0); eg[b].emplace_back(a + n, 0); } vector d1(n, INF); vector d2(n * 2, INF); dijkstra(0, g, d1); dijkstra(0, eg, d2); for (ll i = 0; i < n; i++) { printf("%lld\n", d1[i] + min(d2[i], d2[i + n])); } return 0; /* おまじないを使ったらscanfとprintf関連注意!!!!!!!!!!!! */ }