#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;
const int N = 1010, M = 2e5 + 10;
int n, m;
int s, t, k;
int h[N], rh[N], e[M], ne[M], w[M], idx;
int dist[N];
bool st[N];
int cnt[N];
void add(int h[], int a, int b, int c)
{
e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++;
}
//预估函数f()
void dijkstra()
{
memset(dist, 0x3f, sizeof dist);
memset(st, 0, sizeof st);
priority_queue<PII, vector<PII>, greater<PII>> heap;
dist[t] = 0;
heap.push({0, t});
while (heap.size())
{
PII temp = heap.top();
heap.pop();
int distance = temp.first, id = temp.second;
if (st[id]) continue;
st[id] = true;
for (int i = rh[id]; ~i; i = ne[i])
{
int j = e[i];
if (dist[j] > distance + w[i])
{
dist[j] = distance + w[i];
heap.push({dist[j], j});
}
}
}
}
int astra()
{
priority_queue<PIII, vector<PIII>, greater<PIII>> heap;
heap.push({dist[s], {0, s}});
while (heap.size())
{
PIII temp = heap.top();
heap.pop();
int distance = temp.second.first, id = temp.second.second;
cnt[id] ++;
if (cnt[t] == k) return distance;
for (int i = h[id]; ~i; i = ne[i])
{
int j = e[i];
if (cnt[j] < k)
{
heap.push({w[i] + distance + dist[j], {distance + w[i], j}});
}
}
}
return -1;
}
int main(void)
{
memset(h, -1, sizeof h);
memset(rh, -1, sizeof rh);
cin >> n >> m;
for (int i = 0; i < m; i ++)
{
int a, b, c;
cin >> a >> b >> c;
add(h, a, b, c);
add(rh, b, a, c);
}
cin >> s >> t >> k;
dijkstra();
if (s == t) k ++;
cout << astra() << endl;
return 0;
}