#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <typename T>
struct edge {
    int from, to; T cost;
    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template <class K, class V>
class RadixHeap {
    static constexpr int bit_length = sizeof(K)*8;
    K last;
    size_t sz, cnt;

    array<vector<pair<K, V>>, bit_length> v;
    static inline int bsr(int x){
        return x ? bit_length-__builtin_clz(x) : 0;
    }
    static inline int bsr(ll x){
        return x ? bit_length-__builtin_clzll(x) : 0;
    }

    void pull() {
        if(cnt < v[0].size()) return;;
        int i = 1;
        while(v[i].empty()) i++;
        last = min_element(v[i].begin(),v[i].end())->first;
        for (auto &&x : v[i]) v[bsr(x.first ^ last)].push_back(x);
        v[i].clear();
    }
public:
    RadixHeap() : last(0), sz(0), cnt(0) {}
    void emplace(K x, V val){
        sz++;
        v[bsr(x^last)].emplace_back(x, val);
    }

    pair<K, V> top() {
        pull();
        return v[0][cnt];
    }

    void pop() {
        pull();
        sz--;
        cnt++;
    }

    size_t size() const { return sz; }
    bool empty() const { return !sz; }
};
template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

bool solve(){
    int c, n, m, s, g;
    cin >> c >> n >> m >> s >> g;
    if(!c) return 0;
    s--; g--;
    vector<vector<edge<int>>> G(n);
    for (int i = 0; i < m; ++i) {
        int a, b, f;
        cin >> a >> b >> f;
        a--; b--;
        G[a].emplace_back(b, f);
        G[b].emplace_back(a, f);
    }
    auto dp = make_v(c+1, n, INF<int>);
    dp[0][s] = 0;
    RadixHeap<int, pair<int, int>> Q;
    Q.emplace(0, {0, s});
    while(!Q.empty()){
        int a, x; tie(a, x) = Q.top().second; int C = Q.top().first;
        Q.pop();
        if(dp[a][x] < C) continue;
        for (auto &&e : G[x]) {
            if(a != c){
                if(dp[a+1][e.to] > C+e.cost/2) {
                    dp[a+1][e.to] = C+e.cost/2;
                    Q.emplace(C+e.cost/2, {a+1, e.to});
                }
            }
            if(dp[a][e.to] > C+e.cost){
                dp[a][e.to] = C+e.cost;
                Q.emplace(C+e.cost, {a, e.to});
            }
        }
    }
    int ans = INF<int>;
    for (int i = 0; i <= c; ++i) {
        chmin(ans, dp[i][g]);
    }
    cout << ans << "\n";
    return 1;
}

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