#include #pragma GCC optimize("Ofast") #define _GLIBCXX_DEBUG using namespace std; using std::cout; using std::cin; using std::endl; using ll=long long; using ld=long double; ll I=1167167167167167167; ll Q=1e9+7; #define rep(i,a) for (ll i=0;i using _pq = priority_queue, greater>; template ll LB(vector &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template ll UB(vector &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;} template bool chmax(T &a,const T &b){if(a void So(vector &v) {sort(v.begin(),v.end());} template void Sore(vector &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} template void print_tate(vector &v) {rep(i,v.size()) cout< dijkstra(vector> &G,int start){ int M=G.size(); assert(M>start&&start>=0); vector seen(M,100100100); seen[start]=0; priority_queue,vector>,greater>> pq; pq.push({0,start}); while(!pq.empty()){ len_type time; int ver; tie(time,ver)=pq.top(); pq.pop(); if(seen[ver]>N>>M>>K; vector> G(N); vector> m(N); rep(i,M){ int a,b,c; cin>>a>>b>>c; a--,b--; G[a].push_back({b,c}); G[b].push_back({a,c}); m[a].push_back(c); m[b].push_back(c); } int l=-1,r=200200; while(r-l>1){ int D=(l+r)/2; rep(i,N){ rep(j,G[i].size()){ if(m[i][j]>D) G[i][j].length=1; else G[i][j].length=0; } } auto seen=dijkstra(G,0); if(seen[N-1]