#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;

struct Data{
    int cost,p,tk;
    Data(){}
    Data(int _cost,int _p,int _tk){
        cost=_cost; p=_p; tk=_tk;
    }
    bool operator<(const Data &a)const{
        return cost>a.cost;
    }
};

struct Way{
    int to,cost;
    Way(){}
    Way(int _to,int _cost){
        to=_to; cost=_cost;
    }
};

int main(){
    int C,N,M,S,D,A,B,F;
    while(cin>>C>>N>>M>>S>>D,C||N||M||S||D){
        vector<Way> way[501];
        for(int i=0;i<M;i++){
            cin>>A>>B>>F;
            way[A].push_back(Way(B,F));
            way[B].push_back(Way(A,F));
        }

        priority_queue<Data> q;
        q.push(Data(0,S,0));
        Data q_c;
        bool memo[101][11]={};
        while(!q.empty()){
            q_c = q.top(); q.pop();
            if(q_c.p==D){
                printf("%d\n",q_c.cost);
                break;
            }
            if(memo[q_c.p][q_c.tk]) continue;
            memo[q_c.p][q_c.tk]=true;
            for(int i=0;i<way[q_c.p].size();i++){
                if(q_c.tk<C)
                    q.push(Data(q_c.cost+(way[q_c.p][i].cost)/2,way[q_c.p][i].to,q_c.tk+1));
                q.push(Data(q_c.cost+way[q_c.p][i].cost,way[q_c.p][i].to,q_c.tk));
            }
        }
    }
    return 0;
}