#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;//无向图数组开双倍
const long long INF = 1e18; // 定义一个较大的常数用于初始化距离
typedef pair<long long, pair<int, int>> PII; // {距离, {节点, 免费次数}}
int h[N], ne[N], e[N], w[N], idx;
long long minCostWithFreeFlights[N][15]; // minCostWithFreeFlights[x][op] 表示到 x 点用 op 次免费航线的最小花费
int n, m, k;
void add(int a, int b, int c)
{
e[idx] = b, w[idx] = c;
ne[idx] = h[a];
h[a] = idx++;
}
long long dijkstra(int s, int t)
{
for (int i = 0; i < N; i++)
for (int j = 0; j <= k; j++)
minCostWithFreeFlights[i][j] = INF;
priority_queue<PII, vector<PII>, greater<PII>> heap;
minCostWithFreeFlights[s][0] = 0;
heap.push({0, {s, 0}}); // {距离, {节点, 免费次数}}
while (!heap.empty())
{
auto t = heap.top();
heap.pop();
long long d = t.first;
int ver = t.second.first;
int freeCount = t.second.second;
if (d != minCostWithFreeFlights[ver][freeCount]) continue; // 已更新的点跳过
for(int i=h[ver];i!=-1;i=ne[i])
{
int j=e[i];
int cost=w[i];
// 不使用免费航线
if(minCostWithFreeFlights[j][freeCount] > minCostWithFreeFlights[ver][freeCount] + cost)
{
minCostWithFreeFlights[j][freeCount] = minCostWithFreeFlights[ver][freeCount] + cost;
heap.push({minCostWithFreeFlights[j][freeCount], {j, freeCount}});
}
// 使用免费航线
if(freeCount < k && minCostWithFreeFlights[j][freeCount + 1] > minCostWithFreeFlights[ver][freeCount])
{
minCostWithFreeFlights[j][freeCount + 1] = minCostWithFreeFlights[ver][freeCount];
heap.push({minCostWithFreeFlights[j][freeCount + 1], {j, freeCount + 1}});
}
}
}
// 从 `minCostWithFreeFlights[t][0]` 到 `minCostWithFreeFlights[t][k]` 找到最小值,即最少花费
long long minCost = INF;
for (int i = 0; i <= k; i++) {
minCost = min(minCost, minCostWithFreeFlights[t][i]);
}
return minCost;
}
int main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
memset(h, -1, sizeof h);
cin >> n >> m >> k;
int s, t;
cin >> s >> t;
for (int i = 1; i <= m; i++)
{
int a, b, c;
cin >> a >> b >> c;
add(a, b, c);
add(b, a, c);
}
long long result = dijkstra(s, t);
if (result == INF)
cout << -1 << endl;
else
cout << result << endl;
return 0;
}