#include using namespace std; #define int long long #define pb push_back #define fi first #define se second #define FOR(i,n) for(int i = 0;i=(s);i--) #define all(v) (v).begin(),(v).end() #define chmin(a,b) a=min((a),(b)) #define chmax(a,b) a=max((a),(b)) #define endl '\n' #define IOS() ios_base::sync_with_stdio(0);cin.tie(0) typedef long long ll; typedef pairpint; typedef vectorvint; typedef vectorvpint; const ll MOD=1000000007,INF=1ll<<60; typedef vectorvvint; int N,M; struct edge{ int to,cost; edge(int to,int cost):to(to),cost(cost){} }; vector tree[100010]; ll dist[100010]; int dist2[100010]; void dijkstra(int s){ priority_queue> que; fill(dist,dist+N,INF); dist[s]=0; que.push(pint(0,s)); while(!que.empty()){ pint p=que.top(); que.pop(); int v=p.se; if(dist[v]dist[v]+e.cost){ dist[e.to]=dist[v]+e.cost; que.push(pint(dist[e.to],e.to)); } } } } signed main() { IOS(); cin>>N>>M; vpint v(M); rep(i,0,M){ int a,b,c; cin>>a>>b>>c; a--;b--; if(a>b)swap(a,b); v[i]={a,b}; tree[a].pb({b,c}); tree[b].pb({a,c}); } dijkstra(0); rep(i,0,100010)dist2[i]=INF; rep(i,0,M){ chmin(dist2[i],dist[i]); chmin(dist2[v[i].se],dist[v[i].fi]); } vint ans(N); rep(i,0,N)ans[i]=dist[i]; rep(i,0,N){ tree[0].pb({i,dist2[i]}); tree[i].pb({0,dist2[i]}); } dijkstra(0); rep(i,0,N){ cout<