#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int C, N, M, S, D;

vector<P> G[200];
int d[200][20];
priority_queue<P, std::vector<P>, std::greater<P>> pq;

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

    while(true){
        std::cin >> C >> N >> M >> S >> D;

        if(C == 0){return 0;}
        
        for(int i=0;i<N+1;++i){
            G[i].clear();
        }
    
        for(int i=0;i<M;++i){
            int A, B, F;
            std::cin >> A >> B >> F;

            G[A].emplace_back(B, F, -1);
            G[B].emplace_back(A, F, -1);        
        }

        fill(&d[0][0], &d[0][0] + 200 * 20, 1001001001);
        d[S][0] = 0;
        pq.emplace(0, S, 0);

        while(!pq.empty()){
            int c, u, uu;
            tie(c, u, uu) = pq.top();
            pq.pop();

            if(d[u][uu] < c){continue;}
        
            for(P& p : G[u]){
            
                int v, c2;
                tie(v, c2, ignore) = p;

                // std::cout << u << " -> " << v << ", " << uu << ", " << d[v][uu+1] << ", " << d[u][uu] << ", " << (c2 / 2) << std::endl;
            
                if(d[v][uu] > d[u][uu] + c2){
                    // std::cout << "?" << u << " -> " << v << ", " << uu << ", " << d[v][uu+1] << ", " << d[u][uu] << ", " << (c2 / 2) << std::endl;
                    d[v][uu] = d[u][uu] + c2;
                    pq.emplace(d[v][uu], v, uu);
                }
                if(uu + 1 <= C && d[v][uu+1] > d[u][uu] + c2 / 2){
                    // std::cout << "!" << u << " -> " << v << ", " << uu << ", " << d[v][uu+1] << ", " << d[u][uu] << ", " << (c2 / 2) << std::endl;
                    d[v][uu+1] = d[u][uu] + c2 / 2;
                    pq.emplace(d[v][uu+1], v, uu+1);
                }
            }
        }

        int mn = 1001001001;
        for(int i=0;i<=C;++i){
            mn = min(mn, d[D][i]);
        }

        std::cout << mn << std::endl;
    }
}