#include using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() const int mod = 998244353; const int Mod = 1000000007; const long long INF = 1LL << 60; using ll = long long; using ld = long double; #define v2d(type,H,W,name,value) vector> name(H,vector(W,value)); using plli = pair; struct Edge { int to; ll w; Edge(int to, ll w):to(to),w(w) {} }; using Graph = vector>; template bool chmin(T& a, T b){ if (a>b){ a=b; return true; } else return false; } template bool chmax(T& a, T b){ if (a> N >> M; s=0; Graph G(N+10); rep(i,M){ int a,b,w; cin >> a >> b >> w; a--;b--; G[a].push_back(Edge(b,w)); G[b].push_back(Edge(a,w)); } vector dist(N+10,0); dist[s]=INF; //plli : pair priority_queue que; que.push(make_pair(dist[s],s)); while(!que.empty()){ int v=que.top().second; ll d=que.top().first; que.pop(); if(d=dist[v] for(auto e:G[v]){ if(min(e.w,d)>dist[e.to]){ dist[e.to]=min(e.w,d); que.push(make_pair(dist[e.to],e.to)); } } } cout << dist[N-1] << " "; ll max_w=dist[N-1]; vector dist2(N,-1); dist2[0]=0; queue que2; que2.push(0); while(!que2.empty()){ int qf=que2.front(); for(Edge e:G[qf]){ if(e.w