#include using namespace std; typedef long long ll; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> 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,INF)); d[0][0]=0; priority_queue,int>,vector,int>>,greater,int>>> pq; pq.push({{0,0},0}); while(!pq.empty()){ ll u=pq.top().first.first; int v=pq.top().first.second,w=pq.top().second; pq.pop(); if(u>d[v][w]){ continue; } for(auto x:g[v]){ if(d[x.first][w]>d[v][w]+x.second){ d[x.first][w]=d[v][w]+x.second; pq.push({{d[x.first][w],x.first},w}); } if(!w){ if(d[x.first][1]>d[v][0]){ d[x.first][1]=d[v][0]; pq.push({{d[x.first][1],x.first},1}); } } } } for(int i=0;i