#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;// F -> to, S -> cost
typedef pair<P,int> PP;// F->P(to,cost), S->discount
int c,n,m,s,d;
vector<PP> vec[1000];
int MD[600][13];
const int INF = 999999;

void dijkstra(){
  priority_queue<PP,vector<PP>,greater<PP> > que;
  rep(i,600)rep(j,13)MD[i][j] = INF;
  //syokika
  MD[s][c] = 0;
  que.push(PP(P(0,s),c));//dis,start,discount

  while(!que.empty() ){
    PP p = que.top();que.pop(); //priority_queのPPと
    int v = p.F.S;
    
    for(int i=0;i<vec[v].size();i++){
      PP po = vec[v][i]; //vectorのPPは意味が違うので注意！！！
      //if(MD[v][po.S] < po.F.S)continue;
      if(MD[po.F.F][c] > MD[v][c] + po.F.S){
	MD[po.F.F][c] = MD[v][c]+po.F.S;
	que.push(PP(P(MD[po.F.F][c],po.F.F),c));
      }
      if(po.S > 0 && MD[po.F.F][p.S-1] > MD[v][p.S] + po.F.S/2 ){
	MD[po.F.F][p.S-1] = MD[v][p.S]+po.F.S/2;
	que.push(PP(P(MD[po.F.F][p.S-1],po.F.F),p.S-1));
      }

    }


  }



}


int main(){
  int x,y,co;
  while(true){
    cin >> c >> n >> m >> s >> d;
    if(c+n+m+s+d == 0)break;
    rep(i,1000)vec[i].clear();
    rep(i,m){
      cin >> x >> y >> co;
      vec[x].push_back(PP(P(y,co),c));
      vec[y].push_back(PP(P(x,co),c));
    }
    dijkstra();
    int ans = INF;
    for(int i=0;i<=c;i++){
      ans = min(ans,MD[d][i]);
    }
    cout << ans << endl;
  }
  return 0;
}