#pragma GCC optimize("O3") #pragma GCC optimize ("unroll-loops") #pragma GCC target ("avx") #include constexpr int INF = 2147483647; constexpr long long int INF_LL = 9223372036854775807; constexpr int MOD = 1000000007; using namespace std; typedef long long int ll; typedef unsigned long long int ull; struct edge { ll to; ll cost; }; typedef pair < ll, ll > P; template class RadixHeapInt64 { private: vector< pair > v[65]; ll last, size; int bsr(ull x) { if (x == 0)return -1; return 64 - __builtin_clzll(x); } public: RadixHeapInt64() { last = size = 0; } bool empty() { return size == 0; } //p = {priority,value} void push(ull priority, const T& value) { size++; v[bsr(priority ^ last) + 1].emplace_back(priority,value); } pair pop() { if (!v[0].size()) { int i = 1; while (!v[i].size())i++; last = (*min_element(v[i].begin(), v[i].end())).first; for (int j = 0; j < v[i].size(); j++) { v[bsr(v[i][j].first ^ last) + 1].push_back(v[i][j]); } v[i].clear(); } size--; auto ret = v[0].back(); v[0].pop_back(); return ret; } }; void dijkstra(int s, vector>& g, vector &d) { RadixHeapInt64 q; d = vector(g.size(), INF_LL); d[s] = 0; q.push(0, s); while (!q.empty()) { P p = q.pop(); ll v = p.second; if (d[v] < p.first)continue; for (int i = 0; i < g[v].size(); i++) { edge e = g[v][i]; if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; q.push(d[e.to], e.to); } } } } int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector> g1(N),g2(N*2); for (int i = 0; i < M; i++) { int a, b, c; cin >> a >> b >> c; a--; b--; g1[a].push_back({ b,c }); g1[b].push_back({ a,c }); g2[a].push_back({ b,c }); g2[b].push_back({ a,c }); g2[a].push_back({ b + N,0 }); g2[b].push_back({ a + N,0 }); g2[a + N].push_back({ b + N,c }); g2[b + N].push_back({ a + N,c }); } vector d1(N), d2(N * 2); dijkstra(0, g1, d1); dijkstra(0, g2, d2); for (int i = 0; i < N; i++) { cout << min(d1[i] + d2[i + N], d1[i] * 2) << endl; } }