#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("inline") #include using namespace std; void*wmem; char memarr[96000000]; template inline void walloc1d(T **arr, int x, void **mem = &wmem){ static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] ); (*arr)=(T*)(*mem); (*mem)=((*arr)+x); } template inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){ walloc1d(arr, x2-x1, mem); (*arr) -= x1; } inline int my_getchar_unlocked(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread_unlocked(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = my_getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite_unlocked(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar_unlocked(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); MY_WRITER_VAR.s = 0; } MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; } inline void wt_L(char a){ my_putchar_unlocked(a); } inline void wt_L(int x){ int s=0; int m=0; char f[10]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } struct graph{ int N; int*es; int**edge; void setEdge(int N__, int M, int A[], int B[], void **mem = &wmem){ int i; N = N__; walloc1d(&es, N, mem); walloc1d(&edge, N, mem); for(i=(0);i<(N);i++){ es[i] = 0; } for(i=(0);i<(M);i++){ es[A[i]]++; es[B[i]]++; } for(i=(0);i<(N);i++){ walloc1d(&edge[i], es[i], mem); } for(i=(0);i<(N);i++){ es[i] = 0; } for(i=(0);i<(M);i++){ edge[A[i]][es[A[i]]++] = B[i]; edge[B[i]][es[B[i]]++] = A[i]; } } } ; template struct wgraph{ int N; int*es; int**edge; T**cost; graph g; void setEdge(int N__, int M, int A[], int B[], T C[], void **mem = &wmem){ int i; N = N__; walloc1d(&es, N, mem); for(i=(0);i<(N);i++){ es[i] = 0; } for(i=(0);i<(M);i++){ es[A[i]]++; es[B[i]]++; } walloc1d(&edge, N, mem); for(i=(0);i<(N);i++){ walloc1d(&edge[i], es[i], mem); } walloc1d(&cost, N, mem); for(i=(0);i<(N);i++){ walloc1d(&cost[i], es[i], mem); } for(i=(0);i<(N);i++){ es[i] = 0; } for(i=(0);i<(M);i++){ edge[A[i]][es[A[i]]] = B[i]; edge[B[i]][es[B[i]]] = A[i]; cost[A[i]][es[A[i]]++] = C[i]; cost[B[i]][es[B[i]]++] = C[i]; } g.N = N; g.es = es; g.edge = edge; } template void getDist01(int root, S res[], void *mem = wmem){ int i; int j; int k; int nd; int*q; int qs; int qe; char*don; walloc1d(&q, 2*N, &mem); walloc1d(&don, N, &mem); for(i=(0);i<(N);i++){ res[i] = -1; } for(i=(0);i<(N);i++){ don[i] = 0; } qs = qe = N; q[qe++] = root; res[root] = 0; while(qs < qe){ i = q[qs++]; if(don[i]){ continue; } don[i] = 1; for(j=(0);j<(es[i]);j++){ k = edge[i][j]; nd = res[i] + cost[i][j]; if(res[k]==-1 || res[k] > nd){ res[k] = nd; if(cost[i][j]==0){ q[--qs] = k; } else{ q[qe++] = k; } } } } } int getDist01(int a, int b, void *mem = wmem){ int i; int j; int k; int nd; int*res; int*q; int qs; int qe; char*don; walloc1d(&res, N, &mem); walloc1d(&q, 2*N, &mem); walloc1d(&don, N, &mem); for(i=(0);i<(N);i++){ res[i] = -1; } for(i=(0);i<(N);i++){ don[i] = 0; } qs = qe = N; q[qe++] = a; res[a] = 0; while(qs < qe){ i = q[qs++]; if(i==b){ return res[b]; } if(don[i]){ continue; } don[i] = 1; for(j=(0);j<(es[i]);j++){ k = edge[i][j]; nd = res[i] + cost[i][j]; if(res[k]==-1 || res[k] > nd){ res[k] = nd; if(cost[i][j]==0){ q[--qs] = k; } else{ q[qe++] = k; } } } } return -1; } } ; int N; int M; int K; int A[200000]; int B[200000]; int C[200000]; int d[200000]; wgraph g; int main(){ wmem = memarr; int res; void*mem = wmem; rd(N); rd(M); rd(K); { int Lj4PdHRW; for(Lj4PdHRW=(0);Lj4PdHRW<(M);Lj4PdHRW++){ rd(A[Lj4PdHRW]);A[Lj4PdHRW] += (-1); rd(B[Lj4PdHRW]);B[Lj4PdHRW] += (-1); rd(C[Lj4PdHRW]); } } int e98WHCEY; int cTE1_r3A; int RZTsC2BF; e98WHCEY = 0; cTE1_r3A = 300000; while(e98WHCEY < cTE1_r3A){ int i; if((e98WHCEY + cTE1_r3A)%2==0){ RZTsC2BF = (e98WHCEY + cTE1_r3A) / 2; } else{ RZTsC2BF = (e98WHCEY + cTE1_r3A - 1) / 2; } wmem = mem; for(i=(0);i<(M);i++){ if(C[i] > RZTsC2BF){ d[i] =1; } else{ d[i] =0; } } g.setEdge(N,M,A,B,d); if(g.getDist01(0,N-1) < K){ cTE1_r3A = RZTsC2BF; } else{ e98WHCEY = RZTsC2BF + 1; } } res =cTE1_r3A; wt_L(res); wt_L('\n'); return 0; } // cLay version 20210708-1 // --- original code --- // int N, M, K, A[2d5], B[], C[], d[]; // wgraph g; // { // int res; // void *mem = wmem; // rd(N,M,K,(A--,B--,C)(M)); // res = bsearch_min[int,x,0,3d5][ // wmem = mem; // rep(i,M) d[i] = if[C[i] > x, 1, 0]; // g.setEdge(N,M,A,B,d); // ](g.getDist01(0,N-1) < K); // wt(res); // }