#if defined(_USE_PCH_)
#include "pch.hpp"
#else
#include <bits/stdc++.h>
#endif
#define RNG(V_, A_, B_, ...) for(int V_=(A_), V_##_END=(B_) __VA_OPT__(,) __VA_ARGS__; V_<=V_##_END; V_++)
#define IRNG(V_, A_, B_) for(int V_=(A_), V_##_END=(B_); V_>=V_##_END; V_--)
#ifdef _WIN32
#define long __int64
#endif
#if defined(_LOCAL_) && 0
#undef assert
#define assert(expr) ({ if(!(expr)) asm("int3"); 0; })
#endif
using namespace std;
const int MAXN=3e5+10,INF=0x3f3f3f3f;
void tomin(int& u,int v){ u=min(u,v); }
int n,m;
struct DSU{
int fa[MAXN],mn[MAXN];
void init(){ iota(fa+1,fa+n+1,1),fill(mn+1,mn+n+1,INF); }
int find(int u){ return fa[u]==u?u:fa[u]=find(fa[u]); }
void merge(int u,int v){ assert(u>0&&v>0); (u=find(u))!=(v=find(v)) ? (fa[v]=u,mn[u]=min(mn[u],mn[v])) : 0; }
} dsu;
struct{ int u,v,w; } E[MAXN]; vector<int> G[MAXN]; vector<int> G1[MAXN];
bool vis[MAXN],vise[MAXN]; int mxw;
int fa[MAXN],dep[MAXN],ans[MAXN];
void merge_(int u,int v,int w){
u=dsu.find(u),v=dsu.find(v);
while(u!=v){
assert(v==dsu.find(v));
if(dep[fa[u]]<dep[fa[v]]) swap(u,v);
dsu.merge(fa[u],u),u=dsu.find(u);
}
tomin(dsu.mn[u],w);
tomin(ans[u],dsu.mn[u]+mxw);
}
void dfs(int u){
assert(fa[u]);
dep[u]=dep[fa[u]]+1,vis[u]=1;
tomin(ans[u],dsu.mn[u]+mxw);
for(auto i:G1[u]){
if(vise[i]) continue;
int v=E[i].u^E[i].v^u,w=E[i].w;
if(vis[v]) merge_(u,v,w);
else G[u].push_back(v),fa[v]=u,dsu.mn[v]=w,dfs(v);
}
}
void dfs1(int u){
for(int v:G[u]) tomin(ans[v],ans[u]),dfs1(v);
}
int main(){
#if defined(_LOCAL_)
freopen("in","r",stdin);
// freopen("out","w",stdout);
#else
// freopen("wukong.in","r",stdin);
// freopen("wukong.out","w",stdout);
#endif
ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
cin>>n>>m;
RNG(i,1,m) cin>>E[i].u>>E[i].v>>E[i].w;
sort(E+1,E+m+1,[](auto x,auto y){ return x.w<y.w; });
dep[1]=1,vis[1]=1;
fill(ans+1,ans+n+1,INF);
dsu.init();
RNG(i,1,m){
auto [u,v,w]=E[i]; mxw=w;
if(vis[u]||vis[v]){
if(vis[u]&&vis[v]) merge_(u,v,w);
else{
if(vis[v]) swap(u,v);
fa[v]=u,dsu.mn[v]=w;
dfs(v);
}
}else G1[u].push_back(i),G1[v].push_back(i);
}
dfs1(1);
RNG(i,2,n) cout<<ans[i]<<"\n";
}