1 #include<cstdio>
2 #include<cstdlib>
3 #include<cstring>
4 #include<iostream>
5 #include<algorithm>
6 #include<queue>
7 using namespace std;
8 #define Maxn 10010
9 #define Maxm 50010
10 #define Maxk 25
11 #define INF 0xfffffff
12
13 struct node
14 {
15 int x,y,c,next;
16 }t[2*Maxm];int len=0;
17
18 int first[Maxn];
19 int n,m,k;
20
21 void ins(int x,int y,int c)
22 {
23 t[++len].x=x;t[len].y=y;t[len].c=c;
24 t[len].next=first[x];first[x]=len;
25 }
26
27 int mymin(int x,int y) {return x<y?x:y;}
28
29 int id[Maxn][Maxk],wh[Maxn*Maxk][2];
30 int cnt=0;
31
32 struct hp
33 {
34 int d,x;
35 friend bool operator < (hp x,hp y)
36 {
37 return x.d>y.d;
38 }
39 };
40
41 bool mark[Maxn*Maxk];
42 int dis[Maxn*Maxk];
43 priority_queue<hp > q;
44 void dij(int st)
45 {
46 while(!q.empty()) q.pop();
47 memset(mark,0,sizeof(mark));
48 memset(dis,63,sizeof(dis));
49 q.push((hp){0,st});dis[st]=0;
50 while(!q.empty())
51 {
52 while(!q.empty()&&mark[q.top().x]) q.pop();
53 if(q.empty()) break;
54 hp x=q.top();q.pop();
55 int xx=wh[x.x][0],kk=wh[x.x][1];
56 mark[x.x]=1;
57 for(int i=first[xx];i;i=t[i].next)
58 {
59 int y=t[i].y;
60 if(mark[id[y][kk]]) continue;
61 if(dis[id[y][kk]]>dis[x.x]+t[i].c)
62 {
63 dis[id[y][kk]]=dis[x.x]+t[i].c;
64 q.push((hp){dis[id[y][kk]],id[y][kk]});
65 }
66 if(kk<k)
67 {
68 if(dis[id[y][kk+1]]>dis[x.x])
69 {
70 dis[id[y][kk+1]]=dis[x.x];
71 q.push((hp){dis[id[y][kk+1]],id[y][kk+1]});
72 }
73 }
74 }
75 }
76 }
77
78 int main()
79 {
80 scanf("%d%d%d",&n,&m,&k);
81 memset(first,0,sizeof(first));
82
83 for(int i=1;i<=n;i++)
84 for(int j=0;j<=k;j++)
85 id[i][j]=++cnt,wh[cnt][0]=i,wh[cnt][1]=j;
86
87 for(int i=1;i<=m;i++)
88 {
89 int x,y,c;
90 scanf("%d%d%d",&x,&y,&c);
91 ins(x,y,c);ins(y,x,c);
92 }
93
94 dij(id[1][0]);
95 int ans=INF;
96 for(int i=0;i<=k;i++) ans=mymin(ans,dis[id[n][i]]);
97 printf("%d\n",ans);
98 return 0;
99 }