#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
const int N = 1e3 + 5;
const int M = 1e5 + 5;
int head[N], revhead[N], cnt;
int f[N], st[N];
struct Edge{
int v, w, next;
}edge[M << 1];
struct Node1{
int idx, dist;
bool operator < (const Node1& a) const {
return dist > a.dist;
}
};
struct Node2{
int evalue, idx, dist;
bool operator < (const Node2& a) const {
return evalue > a.evalue;
}
};
void add(int array[], int u, int v, int w)
{
edge[++cnt].v = v;
edge[cnt].w = w;
edge[cnt].next = array[u];
array[u] = cnt;
}
void dijkstra(int s)
{
memset(f, 0x3f, sizeof(f));
priority_queue<Node1> heap;
Node1 start = {s, 0};
heap.push(start);
f[s] = 0;
while (heap.size())
{
Node1 cur = heap.top();
heap.pop();
if (st[cur.idx]) continue;
st[cur.idx] = 1;
for (int i = revhead[cur.idx]; i; i = edge[i].next)
{
int v = edge[i].v;
if (f[v] > cur.dist + edge[i].w)
{
f[v] = cur.dist + edge[i].w;
Node1 next = {v, f[v]};
heap.push(next);
}
}
}
}
int a_star(int s, int e, int k)
{
memset(st, 0, sizeof(st));
priority_queue<Node2> heap;
Node2 start = {f[s], s, 0};
heap.push(start);
while (heap.size())
{
Node2 cur = heap.top();
heap.pop();
if (st[cur.idx] >= k) continue;
st[cur.idx]++;
if (cur.idx == e && st[cur.idx] == k) return cur.dist;
for (int i = head[cur.idx]; i; i = edge[i].next)
{
int v = edge[i].v;
if (st[v] < k)
{
Node2 next = {edge[i].w + cur.dist + f[v], v, edge[i].w + cur.dist};
heap.push(next);
}
}
}
return -1;
}
int main()
{
int n, m;
scanf("%d %d", &n, &m);
for (int i = 0; i < m; ++i)
{
int u, v, w;
scanf("%d %d %d", &u, &v, &w);
add(head, u, v, w);
add(revhead, v, u, w);
}
int s, e, k;
scanf("%d %d %d", &s, &e, &k);
if (s == e) k++;
dijkstra(e);
// for (int i = 1; i <= n; ++i) cout << f[i] << " ";
printf("%d", a_star(s, e, k));
return 0;
}