#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 vector get(vector>> E,int s){ int N = E.size(); vector d(N,Inf64); d[s] = 0; priority_queue,vector>,greater>> Q; Q.emplace(0,s); while(Q.size()>0){ long long D = Q.top().first; int u = Q.top().second; Q.pop(); if(D!=d[u])continue; rep(i,E[u].size()){ int v = E[u][i].first; long long DD = E[u][i].second + D; if(d[v]>DD){ d[v] = DD; Q.emplace(DD,v); } } } return d; } int main(){ int N,M; cin>>N>>M; vector>> E(N),e(N); rep(i,M){ int a,b,c; cin>>a>>b>>c; a--,b--; E[a].emplace_back(b,c); e[b].emplace_back(a,c); } auto d0 = get(E,N-2),d1 = get(E,N-1),d2 = get(e,N-2),d3 = get(e,N-1); rep(i,N-2){ long long ans = Inf64; ans = min(ans,d2[i] + d0[N-1] + d1[i]); ans = min(ans,d3[i] + d1[N-2] + d0[i]); if(ans==Inf64)ans = -1; cout<