#include <bits/stdc++.h>
using namespace std;

struct Edge
{
    int v, w;
};

typedef map<int, vector<Edge>> AdjList;

struct State
{
    int cost, u, stops;

    bool operator>(const State &other) const
    {
        return cost > other.cost;
    }
};

int dijkstra(AdjList &adj, int s, int e, int k)
{
    priority_queue<State, vector<State>, greater<State>> pq;
    map<int, vector<int>> dist;

    for (const auto &p : adj)
    {
        dist[p.first] = vector<int>(k + 2, INT_MAX);
    }

    dist[s][0] = 0;

    pq.push({0, s, 0});

    while (!pq.empty())
    {
        auto [cost, u, stops] = pq.top();

        pq.pop();

        if (u == e)
        {
            return cost;
        }

        if (stops > k)
        {
            continue;
        }

        for (const auto &edge : adj[u])
        {
            int newCost = cost + edge.w;

            if (newCost < dist[edge.v][stops + 1])
            {
                dist[edge.v][stops + 1] = newCost;

                pq.push({newCost, edge.v, stops + 1});
            }
        }
    }

    return -1;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m, k;
    cin >> n >> m >> k;

    int s, e;
    cin >> s >> e;

    AdjList adj;

    for (int i = 1; i <= n; i++)
    {
        adj[i] = {};
    }

    for (int i = 0; i < m; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;

        adj[u].push_back({v, w});
    }

    cout << dijkstra(adj, s, e, k) << '\n';

    return 0;
}
