#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <tuple>
#include <queue>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;
typedef tuple<int, int> P;
typedef tuple<ll, int, int> T;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

template<typename T>
void chmin(T &a, T b) {
    a = min(a, b);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int c, n, m, s, t;
    while (cin >> c >> n >> m >> s >> t, c + n + m + s + t) {
        s--;
        t--;
        vector<vector<P>> G(n);
        REP(i, 0, m) {
            int a, b, f;
            cin >> a >> b >> f;
            a--;
            b--;
            G[a].push_back({b, f});
            G[b].push_back({a, f});
        }
        const ll inf = 1LL << 60;
        auto dist = make_v(n, c + 1, inf);
        priority_queue<T, vector<T>, greater<T>> pq;
        // cost, ticket, vertex
        pq.emplace(0LL, c, s);
        REP(i, 0, c + 1) {
            dist[s][i] = 0;
        }
        while (pq.size()) {
            ll cost;
            int ticket, vertex;
            tie(cost, ticket, vertex) = pq.top();
            pq.pop();
            if (dist[vertex][ticket] < cost) continue;
            dist[vertex][ticket] = cost;
            for (auto p : G[vertex]) {
                int to, f;
                tie(to, f) = p;
                // use ticket
                if (ticket > 0 && dist[to][ticket - 1] > cost + f / 2) {
                    dist[to][ticket - 1] = cost + f / 2;
                    pq.emplace(dist[to][ticket - 1], ticket - 1, to);
                }
                // do not use ticket
                if (dist[to][ticket] > cost + f) {
                    dist[to][ticket] = cost + f;
                    pq.emplace(dist[to][ticket], ticket, to);
                }
            }
        }
        ll ans = inf;
        REP (i, 0, c + 1) {
            chmin(ans, dist[t][i]);
        }
        cout << ans << endl;
    }

    return 0;
}

