#include using namespace std; using ll = long long; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll N,M; cin>>N>>M; vector>> G(N); for(int i=0;i>a>>b>>c; a--;b--; G[a].push_back({b,c}); G[b].push_back({a,c}); } vector> D(N,vector(2,1e18)); D[0][0]=0; priority_queue>,vector>>,greater>>> Q; Q.push({0,{0,0}}); vector> seen(N,vector(2,0)); while(!Q.empty()){ ll c=Q.top().first; auto [n,d]=Q.top().second; Q.pop(); if(seen[n][d])continue; seen[n][d]=1; for(auto [v,w]:G[n]){ if(seen[v][d])continue; if(D[v][d]>c+w){ D[v][d]=c+w; Q.push({c+w,{v,d}}); } } if(d==0){ for(auto [v,w]:G[n]){ if(seen[v][1])continue; if(D[v][1]>c){ D[v][1]=c; Q.push({c,{v,1}}); } } } } for(int i=0;i