#include<algorithm>
#include<iostream>
#include<cstring> //
#include<cstdlib>
#include<cstdio>
#include<queue>
#define nn 10010
#define mm 100010
using namespace std;
int e=0,k;
int dis[nn][25],fir[nn],nxt[mm],to[mm],w[mm];
struct node{
int x,k,d;
bool operator<(const node&b)const{ //priority——queue需要重载小于号
return d>b.d;
}
};
priority_queue<node> q;
int read()
{
int ans=0,f=1;char ch=getchar();
while(!isdigit(ch)) {if(ch==‘-‘) f=-1;ch=getchar();}
while(isdigit(ch)) {ans=ans*10+ch-‘0‘;ch=getchar();}
return ans*f;
}
void add(int u,int v,int ww)
{
nxt[++e]=fir[u];fir[u]=e;to[e]=v;w[e]=ww;
nxt[++e]=fir[v];fir[v]=e;to[e]=u;w[e]=ww;
}
int dijstra(int n)
{
memset(dis,127,sizeof(dis));
q.push((node){1,0,0});
dis[1][0]=0;
while(!q.empty())
{
node o=q.top();q.pop();
if(o.d!=dis[o.x][o.k])
continue;
if(o.x==n)
return o.d;
for(int i=fir[o.x];i;i=nxt[i])
{
if(dis[to[i]][o.k]>dis[o.x][o.k]+w[i])
{
dis[to[i]][o.k]=dis[o.x][o.k]+w[i];
q.push((node){to[i],o.k,dis[to[i]][o.k]});
}
if(o.k<k&&dis[to[i]][o.k+1]>dis[o.x][o.k])
{
dis[to[i]][o.k+1]=dis[o.x][o.k];
q.push((node){to[i],o.k+1,dis[to[i]][o.k+1]});
}
}
}
}
int main()
{
int n,m,u,v,ww;
n=read();m=read();k=read();
for(int i=1;i<=m;i++)
{
u=read();v=read();ww=read();
add(u,v,ww);
}
printf("%d",dijstra(n));
return 0;
}