/*    ∫ ∫ ∫    ノヽ   (_  )  (_    ) (______ )  ヽ(´・ω・)ノ     |  /    UU */ #pragma region macro #include typedef long long int64; using namespace std; using P = pair; typedef vector vi; const int MOD = (int)1e9 + 7; const int64 INF = 1LL << 62; const int inf = 1<<30; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b ostream& operator<<(ostream& os, const vector &V){ int N = V.size(); REP(i,N){ os << V[i]; if (i!=N-1) os << " "; } os << "\n"; return os; } template ostream& operator<<(ostream& os, pair const&P){ os << "("; os << P.first; os << " , "; os << P.second; os << ")"; return os; } template ostream& operator<<(ostream& os, set &S){ auto it=S.begin(); while(it!=S.end()){ os << *it; os << " "; it++; } os << "\n"; return os; } template ostream& operator<<(ostream& os, deque &q){ for(auto it=q.begin();it ostream& operator<<(ostream& os, map const&M){ for(auto e:M){ os<> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)}; #pragma endregion //fixed<> dijkstra(vector>> const& edge, int64 start){ int64 N = edge.size(); vector> dist(N,vector(2,INF)); priority_queue,vector>, greater> > q; //距離、頂点、特権使用回数 q.push(make_tuple(0, start, 0)); vector> visited(N,vector(2,false) ); int64 from,d,skip_cnt; int64 to,cost; while(!q.empty()){ tie(d,from,skip_cnt) = q.top(); q.pop(); if (visited[from][skip_cnt]) continue; visited[from][skip_cnt] = true; dist[from][skip_cnt] = d; for(auto e:edge[from]){ tie(to,cost) = e; if (visited[to][skip_cnt]) continue; if(chmin(dist[to][skip_cnt], int64(d+cost))) q.push(make_tuple(d+cost, to, skip_cnt)); if(skip_cnt==0 and chmin(dist[to][skip_cnt+1], d)) q.push(make_tuple(d, to, skip_cnt+1)); } } return dist; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int N,M; cin >> N >> M; vector>> edge(N); int64 a,b,c; REP(i,M){ cin >> a >> b >> c; edge[--a].emplace_back(--b,c); edge[b].emplace_back(a,c); } auto dist = dijkstra(edge,0); dist[0][1] = 0; REP(i,N){ cout << dist[i][0] + dist[i][1] << bn; } }