#include <bits/stdc++.h>
using namespace std;
// for convenience
using pii = pair<int, int>;
using pipii = pair<int, pii>;
const int inf = 1e9;
/**
* n = จำนวน node ในกราฟ (0..n-1)
* m = จำนวน edge ในกราฟ
* G[u] = list ของ node ที่ติดอยู่กับ u (ตัวแรกคือหมายเลข node, ตัวที่สองคือ weight)
*/
int shortest_path(int n, int m, vector<pii> G[], int k, int s, int t)
{
vector<vector<int>> dist(n, vector<int>(k+1, inf));
vector<vector<bool>> visited(n, vector<bool>(k+1, false));
// push สถานะเริ่มต้นใส่ priority queue ของ dijkstra
dist[s][k] = 0;
priority_queue<pipii, vector<pipii>, greater<pipii>> Q; // min heap (dist[u][f], (u, f))
Q.push({dist[s][k], {s, k}});
while (!Q.empty()) {
int u = Q.top().second.first, f = Q.top().second.second;
Q.pop();
if (visited[u][f])
continue;
visited[u][f] = true;
if (u == t) // end
return dist[u][f];
// เพิ่มการเปลี่ยนสถานะจาก (u, f) ไปสถานะอื่น ๆ ใส่ priority_queue
for (auto vw : G[u]) {
int v = vw.first, w = vw.second;
if (!visited[v][f] && dist[u][f]+w < dist[v][f]) { // เดินตามปกติ
dist[v][f] = dist[u][f]+w;
Q.push({dist[v][f], {v, f}});
}
if (f >= 1 && !visited[v][f-1] && dist[u][f] < dist[v][f-1]) { // ใช้สิทธิ์ผ่านฟรี 1 ครั้ง
dist[v][f-1] = dist[u][f];
Q.push({dist[v][f-1], {v, f-1}});
}
}
}
return -1; // ไม่มีเส้นทางจากจุดเริ่มต้นไปจุดจบ
}
vector<pii> G[100010];
int main()
{
int n, m, k, s, t;
scanf("%d%d%d%d%d", &n, &m, &k, &s, &t);
assert(s >= 0 && s < n);
assert(t >= 0 && t < n);
while (m--) {
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
assert(u >= 0 && u < n);
assert(v >= 0 && v < n);
G[u].push_back({v, w});
}
printf("%d\n", shortest_path(n, m, G, k, s, t));
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW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