1 #include<bits/stdc++.h>
2 using namespace std;
3 #define MAXN 10010
4 #define MAXM 50010
5 #define INF 1e9
6 struct node
7 {
8 int end,value,next;
9 }edge[21*4*MAXM];
10 int cnt,Head[21*MAXN],N,dis[21*MAXN],Heap[21*MAXN],pos[21*MAXN],SIZE,U[MAXM],V[MAXM],VAL[MAXM];
11 void addedge(int bb,int ee,int vv)
12 {
13 edge[++cnt].end=ee;edge[cnt].value=vv;edge[cnt].next=Head[bb];Head[bb]=cnt;
14 }
15 void addedge1(int bb,int ee,int vv)
16 {
17 addedge(bb,ee,vv);addedge(ee,bb,vv);
18 }
19 int read()
20 {
21 int s=0,fh=1;char ch=getchar();
22 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)fh=-1;ch=getchar();}
23 while(ch>=‘0‘&&ch<=‘9‘){s=s*10+(ch-‘0‘);ch=getchar();}
24 return s*fh;
25 }
26 void Push1(int k)
27 {
28 int now=k,root;
29 while(now>1)
30 {
31 root=now/2;
32 if(dis[Heap[root]]<=dis[Heap[now]])return;
33 swap(Heap[root],Heap[now]);
34 swap(pos[Heap[root]],pos[Heap[now]]);
35 now=root;
36 }
37 }
38 void Insert(int k)
39 {
40 Heap[++SIZE]=k;pos[k]=SIZE;Push1(SIZE);
41 }
42 void Pop1(int k)
43 {
44 int now,root=k;
45 pos[Heap[k]]=0;Heap[k]=Heap[SIZE--];if(SIZE>0)pos[Heap[k]]=k;
46 while(root<=SIZE/2)
47 {
48 now=root*2;
49 if(now<SIZE&&dis[Heap[now+1]]<dis[Heap[now]])now++;
50 if(dis[Heap[root]]<=dis[Heap[now]])return;
51 swap(Heap[root],Heap[now]);
52 swap(pos[Heap[root]],pos[Heap[now]]);
53 root=now;
54 }
55 }
56 void dijkstra(int start)
57 {
58 int i,v,u;
59 for(i=1;i<=N;i++)dis[i]=INF;dis[start]=0;
60 for(i=1;i<=N;i++)Insert(i);
61 while(SIZE>0)
62 {
63 u=Heap[1];Pop1(pos[u]);
64 for(i=Head[u];i!=-1;i=edge[i].next)
65 {
66 v=edge[i].end;
67 if(dis[v]>dis[u]+edge[i].value){dis[v]=dis[u]+edge[i].value;Push1(pos[v]);}
68 }
69 }
70 }
71 int main()
72 {
73 int n,m,i,MN,j,k;
74 n=read();m=read();k=read();
75 for(i=1;i<=m;i++)
76 {
77 U[i]=read();V[i]=read();VAL[i]=read();
78 }
79 memset(Head,-1,sizeof(Head));cnt=1;
80 N=(k+1)*n;
81 for(i=0;i<=k;i++)
82 {
83 for(j=1;j<=m;j++)addedge1(i*n+U[j],i*n+V[j],VAL[j]);
84 if(i!=k)
85 {
86 for(j=1;j<=m;j++){addedge(i*n+U[j],(i+1)*n+V[j],0);addedge(i*n+V[j],(i+1)*n+U[j],0);}
87 }
88 }
89 dijkstra(1);
90 MN=INF;
91 for(i=0;i<=k;i++)MN=min(MN,dis[i*n+n]);
92 printf("%d",MN);
93 fclose(stdin);
94 fclose(stdout);
95 return 0;
96 }