#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define F first
#define S second


int c,n,m,s,d;
typedef struct{
  int to,cost;
}edge;

vector<edge> V[11*100];


int dijkstra(int from,int to){
  from=(c+1)*from+c;
  bool used[n*(c+1)];
  memset(used,0,sizeof(used));
  int len[n*(c+1)];
  rep(i,n*(c+1))len[i]=1<<23;
  len[from]=0;

  priority_queue<PI,vector<PI>,greater<PI> > Q;
  Q.push(mp(0,from));
  while(!Q.empty()){
    int cost=Q.top().F,tfrom=Q.top().S;Q.pop();
    if(used[tfrom])continue;
    used[tfrom]=true;
    rep(i,V[tfrom].size()){
      int tto=V[tfrom][i].to,tcost=V[tfrom][i].cost;
      if(used[tto])continue;
      len[tto]=min(len[tfrom]+tcost,len[tto]);
      Q.push(mp(len[tto],tto));
    }
  }
/*
  rep(i,n){
    rep(j,c+1)printf("%6d",len[i*(c+1)+j]);
    cout<<endl;
  }
*/
  int ans=len[to*(c+1)];
  rep(i,c+1)ans=min(ans,len[to*(c+1)+i]);
  return ans;
}

main(){
  while(cin>>c>>n>>m>>s>>d,c|n|m|s|d){
    --s,--d;
    rep(i,n*(c+1))V[i].clear();

    rep(j,m){
      int a,b,cost;
      cin>>a>>b>>cost;
      --a,--b;
      rep(i,c+1){
        V[a*(c+1)+i].pb((edge){b*(c+1)+i,cost});
        V[b*(c+1)+i].pb((edge){a*(c+1)+i,cost});
        if(i){
          V[a*(c+1)+i].pb((edge){b*(c+1)+i-1,cost/2});
          V[b*(c+1)+i].pb((edge){a*(c+1)+i-1,cost/2});
        }
      }
    }
/*
    rep(i,n*(c+1)){
      printf("%d ",i/(c+1)+1);
      rep(j,V[i].size()){
        printf("%d %6d ",V[i][j].to/(c+1)+1,V[i][j].cost);
      }
      cout<<endl;
    }
*/
    cout<<dijkstra(s,d)<<endl;
  }
}