1 #include<cstdio>
2 #include<queue>
3 #include<cstring>
4 #include<iostream>
5 #define maxn 1000000
6 using namespace std;
7
8 struct edge{
9 int from,u,v,len;
10 }e[maxn];
11
12 int tot,first[maxn],n,m,k,dis[maxn];
13 void insert(int u,int v,int len){
14 tot++;
15 e[tot].from = first[u];
16 e[tot].u = u;
17 e[tot].v = v;
18 e[tot].len = len;
19 first[u] = tot;
20 }
21
22 int inf = 0x3f3f3f3f;
23 bool book[maxn];
24 int SPFA(int line){
25 memset(book,false,sizeof(book));
26 for(int i = 1;i <= n;i++) dis[i] = inf;
27
28 queue<int> Q;
29 dis[1] = 0;
30 book[1] = true;
31 Q.push(1);
32
33 while(!Q.empty()){
34 int p = Q.front();
35 Q.pop();
36 for(int i = first[p];i;i = e[i].from){
37 int v = e[i].v,s;
38 if(e[i].len > line) s = dis[p]+1;
39 else s = dis[p];
40
41 if(dis[v] > s){
42 dis[v] = s;
43 if(!book[v]){
44 book[v] = true;
45 Q.push(v);
46 }
47 }
48 }
49 book[p] = false;
50 }
51
52 if(dis[n] > k) return 0;
53 else return 1;
54 }
55
56 int main(){
57 int ans = -1;
58 scanf("%d%d%d",&n,&m,&k);
59
60 for(int i = 1;i <= m;i++){
61 int a,b,c;
62 scanf("%d%d%d",&a,&b,&c);
63 insert(a,b,c);
64 insert(b,a,c);
65 }
66
67 int L = 0,R = 1000000,mid = (L+R)/2;
68 while(L <= R){
69 mid = (L+R)/2;
70 if(SPFA(mid)) ans = mid,R = mid-1;
71 else L = mid+1;
72 // if(SPFA(mid)) R = mid;
73 // else L = mid;
74 }
75
76 printf("%d",ans);
77
78 return 0;
79 }