#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
const int N = 10009;
const int M = 1000009;
const int INF = 0x7fffffff;
struct edge{
int to,nex,dis;
bool operator <(const edge &t) const{
return dis>t.dis;
}
} L[M],RL[M];
struct node{
int to,dis;
bool operator<(const node &t) const{
return dis>t.dis;
}
};
struct node1{
int to,f,dis;
bool operator <(const node1 &t) const{
if(f==t.f) return dis>t.dis;
return f>t.f;
}
};
int F[N],RF[N],cnt,Rcnt;
int n,m,ST,EN,K;
void add(int f,int t,int dis){
L[cnt].dis = dis;
L[cnt].nex = F[f];
L[cnt].to = t;
F[f] = cnt++;
RL[Rcnt].dis = dis;
RL[Rcnt].nex = RF[t];
RL[Rcnt].to = f;
RF[t] = Rcnt++;
}
int dis[N];
bool in[N];
void dijkstra(int st){
for(int i=0; i<=n; i++) dis[i] = INF;
priority_queue<node> que;
while(!que.empty()) que.pop();
node t,e;
e.dis = 0,e.to = st;
que.push(e);
memset(in,0,sizeof(in));
dis[st] = 0;
in[st] = true;
while(!que.empty()){
e = que.top();
que.pop();
in[e.to] = false;
for(int i = RF[e.to]; i!=-1; i=RL[i].nex){
if(dis[RL[i].to]>dis[e.to]+RL[i].dis){
dis[RL[i].to]=dis[e.to]+RL[i].dis;
if(!in[RL[i].to]){
in[RL[i].to]=true;
t.to = RL[i].to;
t.dis =dis[e.to]+RL[i].dis;
que.push(t);
}
}
}
}
}
int a_star(){
if(dis[ST]==INF) return -1;
if(ST==EN) K++;
priority_queue<node1> que;
while(!que.empty()) que.pop();
node1 e,t;
e.dis =0;
e.to=ST,e.f = 0;
que.push(e);
int C=0,i;
while(!que.empty()){
e=que.top();
que.pop();
if(e.to==EN) C++;
if(C==K) return e.dis;
for(i=F[e.to]; i!=-1; i=L[i].nex){
t.dis =e.dis+L[i].dis;
t.f = t.dis+dis[L[i].to];
t.to=L[i].to;
que.push(t);
}
}
return -1;
}
int main(){
freopen("in.txt","r",stdin);
while(~scanf("%d%d",&n,&m)){
cnt=1;
Rcnt=1;
memset(F,-1,sizeof(F));
memset(RF,-1,sizeof(RF));
int f,t,dis;
for(int i=0; i<m; i++){
scanf("%d%d%d",&f,&t,&dis);
add(f,t,dis);
}
scanf("%d%d%d",&ST,&EN,&K);
dijkstra(EN);
printf("%d\n",a_star());
}
return 0;
}