WA on #3,4,7,8,9
#include <bits/stdc++.h>
#define re register int
#define min(x, y) (x < y ? x : y)
using namespace std;
typedef pair<int, int> pii;
const int N = 21 * (1e4 + 10);
const int M = 62 * (5e4 + 10);
const int inf = 0x3f3f3f3f;
struct edge
{
int to, w, next;
}e[M];
int top, h[N], dist[N];
int n, m, k, s, t, a[N], b[N], c[N];
bool vis[N];
priority_queue<pii, vector<pii>, greater<pii> > q;
void add(int x, int y, int w)
{
++top;
e[top].to = y;
e[top].w = w;
e[top].next = h[x];
h[x] = top;
}
void build()
{
for (re p = 0; p < k; p ++)
{
for (re x = 1 + p * n; x <= n + p * n; x ++)
{
for (re i = h[x]; i; i = e[i].next)
{
int y = e[i].to;
y += ((p + 1) * n);
add(x, y, 0);
// add(y, x, 0); <--- tip 1
}
}
for (re i = 1; i <= m; i ++)
{
int delta = (p + 1) * n;
add(a[i] + delta, b[i] + delta, c[i]);
add(b[i] + delta, a[i] + delta, c[i]);
}
}
n = n * (k + 1);
}
void dijkstra()
{
for (re i = 1; i <= n; i ++) dist[i] = inf;
dist[s] = 0;
q.push({0, s});
while (!q.empty())
{
int x = q.top().second; q.pop();
if (vis[x]) continue;
vis[x] = true;
for (re i = h[x]; i ; i = e[i].next)
{
int y = e[i].to, w = e[i].w;
if (dist[x] + w < dist[y])
{
dist[y] = dist[x] + w;
q.push({dist[y], y});
}
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> m >> k >> s >> t;
s ++;
t ++;
for (re i = 1; i <= m; i ++)
{
cin >> a[i] >> b[i] >> c[i];
a[i] ++;
b[i] ++;
add(a[i], b[i], c[i]);
add(b[i], a[i], c[i]);
}
int nn = n; // <--- tip 3
build();
dijkstra();
// cout << dist[t * (k + 1)]; <--- tip 2
int ans = inf;
for (re i = 0; i <= k; i ++)
{
ans = min(ans, dist[t + i * nn]);
}
cout << ans;
return 0;
}