#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

struct edge {
    int to, cost;
    edge() {}
    edge(int to_, int cost_): to(to_), cost(cost_) {}
};

struct state {
    int pos, cost;
    state (){}
    state (int pos_, int cost_): pos(pos_), cost(cost_) {}

    bool operator < (const state& o) const {
        return cost > o.cost;
    }
};

constexpr int INF = 1 << 29;

int C, M, N, S, D;

const int W = 100;
vector<edge> graph[1100];

int min_cost[1100];

bool solve() {
    cin >> C >> N >> M >> S >> D;
    if (C+N+M+S+D == 0) { return false; }
    --S; --D;

    for (int j = 0; j < M; ++j) {
        int a, b, f; cin >> a >> b >> f;
        --a; --b;
        for (int j = 0; j < C; ++j) {
            graph[a+j*W].emplace_back(b+j*W, f);
            graph[b+j*W].emplace_back(a+j*W, f);

            graph[a+j*W].emplace_back(b+(j+1)*W, f/2);
            graph[b+j*W].emplace_back(a+(j+1)*W, f/2);
        }
        graph[a+C*W].emplace_back(b+C*W, f);
        graph[b+C*W].emplace_back(a+C*W, f);
    }

    fill(min_cost, min_cost+1100, INF);
    min_cost[S] = 0;

    priority_queue<state, vector<state>> que;
    que.emplace(S, 0);

    while (!que.empty()) {
        state st = que.top(); que.pop();
        int pos = st.pos;
        int cost = st.cost;
        if (cost > min_cost[st.pos]) { continue; }

        for (edge& e : graph[pos]) {
            int next_cost = cost + e.cost;
            if (next_cost < min_cost[e.to]) {
                min_cost[e.to] = next_cost;
                que.emplace(e.to, next_cost);
            }
        }
    }

    int ans = INF;
    for (int j = 0; j <= C; ++j) {
        ans = min(ans, min_cost[D+j*W]);
    }
    cout << ans << endl;

    return true;
}

int main() {
    for (; solve(); ) ;
    return 0;
}