/*
第k短路的问题, 用A*+dij就可以。
*/
#include<cstdio>
#include<cstring>#include<vector>
#include<queue>
#define INF 1<<30
using namespace std;
struct Edge
{
int from,to,dist;
} a[110*110];
struct Node
{
int u,g,w;
bool operator < (const Node &as) const
{
return w>as.w;
}
};
int n,m,s,t,k,d[110],tol[110];
vector<Edge> edges;
vector<int> G[110];
int add(int x,int y,int z)
{
edges.push_back((Edge)
{
x,y,z
});
int l = edges.size();
G[x].push_back(l-1);
}
int bfs()
{
int vis[110];
for(int i = 0; i <= n; i++)
d[i] = INF;
memset(vis,0,sizeof(vis));
priority_queue<Node> q;
d[t] = 0;
q.push((Node)
{
t,0,0
});
while(!q.empty())
{
Node ts = q.top();
q.pop();
int u = ts.u;
if(vis[u]) continue;
vis[u] = 1;
for(int i = 0; i < G[u].size(); i++)
{
Edge &e = edges[G[u][i]];
int v = e.to;
if(d[v]>d[u]+e.dist)
{
d[v]=d[u]+e.dist;
q.push((Node)
{
v,0,d[v]
});
}
}
}
}
int A_star()
{
int i;
if(d[s]==INF)return -1;
priority_queue<Node>que;
memset(tol,0,sizeof(tol));
que.push((Node)
{
s,0,0
});
while(!que.empty())
{
Node a=que.top();
que.pop();
int u=a.u;
tol[u]++;
if(a.u==t)
//printf("%d %d!~\n",a.w,tol[u]);
if(tol[t]==k) return a.w;
if(tol[u]>k) continue;
for(i=0; i<G[u].size(); i++)
{
Edge &e=edges[G[u][i]];
int v=e.to;
//printf("%d..\n",a.g+e.dist+d[v]);
que.push((Node)
{
v,a.g+e.dist,a.g+e.dist+d[v]
});
}
}
return -1;
}
int main()
{
while(scanf("%d%d",&n,&m)==2)
{
if(!n&&!m) break;
edges.clear();
for(int i = 0; i <= n; i++)
G[i].clear();
scanf("%d%d%d",&s,&t,&k);
for(int i = 0; i < m; i++)
{
scanf("%d%d%d",&a[i].from,&a[i].to,&a[i].dist);
add(a[i].to,a[i].from,a[i].dist);
}
bfs();
//printf("%d..\n",d[s]);
edges.clear();
for(int i = 0; i <= n; i++)
G[i].clear();
for(int i = 0; i < m; i++)
{
add(a[i].from,a[i].to,a[i].dist);
}
int tp = A_star();
printf("%d\n",tp);
}
return 0;
}