#pragma GCC optimize("Ofast") #include using namespace std; #define rep(i, n) for(int i = 0; i < (n); ++i) #define all(x) (x).begin(),(x).end() #define ln '\n' const long long MOD = 1000000007LL; //const long long MOD = 998244353LL; typedef long long ll; typedef unsigned long long ull; typedef pair pii; typedef pair pll; template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; } template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; } /////////////////////////////////////////////////////////////////////////////////////////////////// template struct edge { int src,to; T cost; edge() = default; edge(int to, T cost) : src(-1), to(to), cost(cost) {} edge(int src, int to, T cost) : src(src), to(to), cost(cost) {} bool operator<(const edge &e) const { return cost < e.cost; } }; ll dist[101010][2]; using Tu = tuple; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N,M; cin >> N >> M; vector>> G(N); rep(i,M) { int a,b,c; cin >> a >> b >> c; --a; --b; G[a].emplace_back(b,c); G[b].emplace_back(a,c); } priority_queue, greater> pq; pq.emplace(make_tuple(0,0,0)); rep(i,N) rep(j,2) dist[i][j] = 1e18; dist[0][0] = dist[0][1] = 0; while (!pq.empty()) { ll d,v,n; tie(d,v,n) = pq.top(); pq.pop(); if (d > dist[v][n]) continue; for (auto &e : G[v]) { if (chmin(dist[e.to][n],dist[v][n] + e.cost)) { pq.emplace(make_tuple(dist[e.to][n],e.to,n)); } if (n == 0 && chmin(dist[e.to][1],dist[v][0])) { pq.emplace(make_tuple(dist[e.to][1],e.to,1)); } } } rep(i,N) { cout << dist[i][0] + dist[i][1] << ln; } }