#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i, n) for (int i = 0; i < (int)(n); ++i) //#define cerr if(false) cerr #define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__); using namespace std; using ll = long long; using pii = pair; template ostream &operator<<(ostream &os, pair a){ os << '(' << a.first << ',' << a.second << ')'; return os; } template ostream &operator<<(ostream &os, vector v){ for(auto x:v)os << x << ' '; return os; } void debug(){cerr << '\n';} template void debug(H a, T... b){ cerr << a; if(sizeof...(b))cerr << ", "; debug(b...); } struct edge{ int to, cost; edge(int a = 0, int b = 0) : to(a), cost(b) {} }; auto dijkstra(int s,vector>&g){ int n = (int)g.size(); vector>dist(2); rep(i,2)dist[i].resize(n,1LL<<60); // vector way(n,0); using ll_i = pair; priority_queue,greater>pq; dist[0][s] = 0; dist[1][s] = 0; // way[s] = 1; rep(i,2)pq.push({dist[i][s],pii(i,s)}); while(!pq.empty()){ auto a = pq.top(); pq.pop(); int s = a.second.first; int v = a.second.second; if(a.first > dist[s][v])continue; for(auto &x:g[v]){ if(dist[s][x.to] > dist[s][v] + x.cost){ dist[s][x.to] = dist[s][v] + x.cost; // way[x.to] = 0; pq.push({dist[s][x.to], pii(s,x.to)}); } if(s == 0){ if(dist[1][x.to] > dist[s][v]){ dist[1][x.to ] = dist[s][v]; // way[x.to] = 0; pq.push({dist[1][x.to], pii(1,x.to)}); } } // if(dist[x.to] == dist[v] + x.cost){ // way[x.to] += way[v]; // way[x.to] %= mod; // } } } // return {dist, way}; return dist; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n,m; cin >> n >> m; vector>g; g.resize(n); rep(i,m){ int a,b; ll c; cin >> a >> b >> c; a--,b--; g[a].emplace_back(b,c); g[b].emplace_back(a,c); } auto d = dijkstra(0, g); rep(i,n){ cout << d[0][i] + d[1][i] << "\n"; } }