#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }


struct edge
{
  int to, cost;
  edge(int to, int cost) : to(to), cost(cost) {}
};

struct P
{
  int pnt, ticket, cost;
  P(int pnt = 0, int ticket = 0, int cost = 0) : pnt(pnt), ticket(ticket), cost(cost) {}
};

bool operator>(const P& left, const P& right)
{
  return left.cost > right.cost;
}

int D[16][128];

int main()
{
  int c, n, m, s, d;
  while(cin >> c >> n >> m >> s >> d && c){
    memset(D, -1, sizeof D);
    vector<vector<edge> > edges(n);

    rep(i, m){
      int a, b, f;
      cin >> a >> b >> f;

      edges[a - 1].push_back(edge(b - 1, f));
      edges[b - 1].push_back(edge(a - 1, f));
    }

    priority_queue<P, vector<P>, greater<P> > que;
    for(que.push(P(s - 1, c, 0)); !que.empty(); que.pop()){
      P v = que.top();

      if(D[v.ticket][v.pnt] != -1 && D[v.ticket][v.pnt] <= v.cost) continue;
      D[v.ticket][v.pnt] = v.cost;
      
      rep(i, edges[v.pnt].size()){
	int to = edges[v.pnt][i].to, cost = edges[v.pnt][i].cost;

	que.push(P(to, v.ticket, v.cost + cost));
	if(0 < v.ticket) que.push(P(to, v.ticket - 1, v.cost + cost / 2));
      }
    }

    int ans = 1 << 30;
    rep(i, c+1) if(D[i][d - 1] != -1) chmin(ans, D[i][d - 1]);

    cout << ans << endl;
  }
}