#include using namespace std; #include using namespace atcoder; using ll=long long; using Graph=vector>>; #define MOD 998244353 #define INF 1000000000 #define MAX 1000000 int main(){ int n,m; cin>>n>>m; Graph G(n); for(int i=0;i>s>>t>>d; s--;t--; G[s].push_back(make_pair(t,d)); G[t].push_back(make_pair(s,d)); } int left=1; int right=1000000001; while(left+1 dist(n,INF); dist[0]=0; queue q; q.push(0); while(!q.empty()){ int v=q.front(); q.pop(); for(auto e:G[v]){ int nv=e.first; int d=e.second; if(ddist[v]+1){ dist[nv]=dist[v]+1; q.push(nv); } } } if(dist[n-1]==INF){ right=x; }else{ left=x; } } int x=left; vector dist(n,INF); dist[0]=0; queue q; q.push(0); while(!q.empty()){ int v=q.front(); q.pop(); for(auto e:G[v]){ int nv=e.first; int d=e.second; if(ddist[v]+1){ dist[nv]=dist[v]+1; q.push(nv); } } } cout<