1 uses math;
2 const maxn=1000+200;
3 type node=record
4 go,next,w:longint;
5 end;
6 var d,head:array[0..maxn] of longint;
7 v:array[0..maxn] of boolean;
8 q:array[0..10*maxn] of longint;
9 e:array[0..20000] of node;
10 i,n,m,k,l,r,x,y,z,mid,tot,ll,rr:longint;
11 procedure insert(x,y,z:longint);
12 begin
13 inc(tot);
14 e[tot].go:=y;e[tot].w:=z;e[tot].next:=head[x];head[x]:=tot;
15 end;
16
17 function spfa(val:longint):boolean;
18 var i,x,y,tmp:longint;
19 begin
20 fillchar(d,sizeof(d),60);
21 fillchar(v,sizeof(v),false);
22 l:=0;r:=1;q[1]:=1;d[1]:=0;v[1]:=true;
23 while l<r do
24 begin
25 l:=l+1;
26 x:=q[l];v[x]:=false;
27 i:=head[x];
28 while i<>0 do
29 begin
30 y:=e[i].go;
31 if e[i].w>val then tmp:=d[x]+1 else tmp:=d[x];
32 if tmp<d[y] then
33 begin
34 d[y]:=tmp;
35 if not(v[y]) then
36 begin
37 v[y]:=true;
38 r:=r+1;
39 q[r]:=y;
40 end;
41 end;
42 i:=e[i].next;
43 end;
44 end;
45 exit(d[n]<=k);
46 end;
47 procedure init;
48 begin
49 readln(n,m,k);
50 for i:=1 to m do
51 begin
52 readln(x,y,z);
53 insert(x,y,z);insert(y,x,z);
54 end;
55 end;
56 procedure main;
57 begin
58 ll:=0;rr:=1000000+1;
59 while ll<rr do
60 begin
61 mid:=(ll+rr)>>1;
62 if spfa(mid) then rr:=mid else ll:=mid+1;
63 end;
64 if ll>1000000 then writeln(‘-1‘) else writeln(ll);
65 end;
66
67 begin
68 assign(input,‘input.txt‘);assign(output,‘output.txt‘);
69 reset(input);rewrite(output);
70 init;
71 main;
72 close(input);close(output);
73 end.