struct Edge//存放边
{
int a,b,w;
}edges[M];
edges[i]={a,b,w};
//结构体经典赋值方式
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=510;
const int M=10010;
int n,m,k;
int dist[N];//记录到第一个点的距离
int last[N];//记录上一次的备份
struct Edge//存放边
{
int a,b,w;
}edges[M];
void bellman_ford()
{
memset(dist , 0x3f , sizeof dist);
dist[1]=0;//赋初值
for(int i=0;i<k;i++)//循环k次,因为要求最多走k条边,每次遍历的是边,加备份的数据,也就是只更新了离起点只有一条边得所有点的距离,
//循环第二次就更新离起点有两条边的所有点的距离
{
memcpy(last,dist,sizeof dist);
for(int j=0;j<m;j++)
{
auto e=edges[j];//依次由循环取出所有边进行距离的更新·
dist[e.b]=min(dist[e.b],last[e.a]+e.w);
}
}
}
int main()
{
scanf("%d%d%d",&n,&m,&k);
int a,b,w;
for(int i=0;i<m;i++)
{
scanf("%d%d%d",&a,&b,&w);
edges[i]={a,b,w};
}
bellman_ford();
if(dist[n]>=0x3f3f3f3f/2) puts("impossible");//最大值可能因为负权边的存在而变小,所以用这个比较数据
else
printf("%d\n",dist[n]);
return 0;
}