#include #include using namespace std; #define ll long long #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++) #define revrep(i,n) for(int (i)=(n)-1;i>=0; i--) // example const ll inf=1e15; void dijkstra(int s, map>& g, vector>& dist,const ll inf, const ll zero) { int n=dist[0].size(); vector> visited = vector>(2, vector(n)); fill(dist[0].begin(),dist[0].end(),inf); fill(dist[1].begin(),dist[1].end(),inf); using P = tuple; priority_queue, greater

> pq; dist[0][s]=zero; dist[1][s]=zero; //visited[s]=true; pq.push(make_tuple(0,s,0)); pq.push(make_tuple(0,s,1)); while(!pq.empty()) { int v,b; ll d; tie(d,v,b)=pq.top(); pq.pop(); if(visited[b][v]) continue; visited[b][v]=true; for(auto& uw : g[v]) { int u; ll w; tie(u,w)=uw; if(b==0) { if(visited[0][u])continue; if(d& min_c, vector>& ng,map>& g) { // we have min_c[s] for(auto& u : ng[s]) { min_c[u]=min(min_c[s],g[s][u]); dfs(u,min_c,ng,g); } } int main() { cin.tie(0); ios::sync_with_stdio(false); cout<::max_digits10); int n,m; cin>>n>>m; map> g; rep(i,m) { ll a,b,c; cin>>a>>b>>c; g[a-1][b-1]=c; g[b-1][a-1]=c; } vector> dist = vector>(2,vector(n)); const ll inf=1e15; dijkstra(0,g,dist,inf,0LL); rep(i,n) { cout << dist[0][i]+dist[1][i]<