1 #include <cstdio>
2 #include <queue>
3
4 #define min(a,b) (a<b?a:b)
5
6 inline void read(int &x)
7 {
8 x=0; register char ch=getchar();
9 for(; ch>‘9‘||ch<‘0‘; ) ch=getchar();
10 for(; ch>=‘0‘&&ch<=‘9‘; ch=getchar()) x=x*10+ch-‘0‘;
11 }
12 const int M(10005);
13 const int N(1005);
14 int n,k,p;
15 int head[N],sumedge;
16 struct Edge {
17 int v,next,w;
18 Edge(int v=0,int next=0,int w=0):v(v),next(next),w(w){}
19 }edge[M<<1];
20 inline void ins(int u,int v,int w)
21 {
22 edge[++sumedge]=Edge(v,head[u],w),head[u]=sumedge;
23 edge[++sumedge]=Edge(u,head[v],w),head[v]=sumedge;
24 }
25
26 bool inq[N];
27 int dis[N];
28 std::queue<int>que;
29 int L,R,Mid,ans=-1;
30 inline bool check(int lim)
31 {
32 for(int i=1; i<=n; ++i)
33 dis[i]=0x3f3f3f3f,inq[i]=0;
34 for(; !que.empty(); ) que.pop();
35 int cnt=0; que.push(1); dis[1]=0;
36 for(int u,v; !que.empty(); )
37 {
38 u=que.front(); que.pop(); inq[u]=0;
39 for(int i=head[u]; i; i=edge[i].next)
40 {
41 v=edge[i].v;
42 cnt=(edge[i].w>lim);
43 if(dis[v]>dis[u]+cnt)
44 {
45 dis[v]=dis[u]+cnt;
46 if(!inq[v]) inq[v]=1,que.push(v);
47 }
48 }
49 }
50 return dis[n]<=k;
51 }
52
53 int Presist()
54 {
55 read(n),read(p),read(k);
56 for(int u,v,w,i=1; i<=p; ++i)
57 read(u),read(v),read(w),ins(u,v,w),R=R>w?R:w;;
58 for(; L<=R; )
59 {
60 Mid=L+R>>1;
61 if(check(Mid))
62 {
63 ans=Mid;
64 R=Mid-1;
65 }
66 else L=Mid+1;
67 }
68 printf("%d\n",ans);
69 return 0;
70 }
71
72 int Aptal=Presist();
73 int main(int argc,char**argv){;}