#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#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()
const int INF = 1<<30;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef pair<Edge, int> P;

int dijkstra2(const Graph &g, int c, int s, int t) {
  int n = g.size();
  vector<Weight> dist[c+1];
  REP(i,c+1)
    dist[i].assign(n, INF);
  dist[c][s] = 0;
  priority_queue<P> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(P(Edge(-2, s, 0),c)); !Q.empty(); ) {
    Edge e = Q.top().first;
    int cc = Q.top().second;
    Q.pop();
    FOR(f,g[e.dst]) {
      if (dist[cc][f->dst] > e.weight+f->weight) {
        dist[cc][f->dst] = e.weight+f->weight;
        Q.push(P(Edge(f->src, f->dst, e.weight+f->weight),cc));
      }
      if (cc > 0 && dist[cc-1][f->dst] > e.weight+f->weight/2) {
        dist[cc-1][f->dst] = e.weight+f->weight/2;
        Q.push(P(Edge(f->src, f->dst, e.weight+f->weight/2),cc-1));
      }      
    }
  }
  int res = INF;
  REP(i,c+1) {
    res = min(dist[i][t], res);
  }
  return res;
}

int main() {
  int c,n,m,s,d;
  while(cin>>c>>n>>m>>s>>d,c) {
    s--;d--;
    Graph g(n);
    REP(i,m) {
      int a,b,f;
      cin >> a >> b >> f;
      a--;b--;
      g[a].push_back(Edge(a,b,f));
      g[b].push_back(Edge(b,a,f));
    }
    cout << dijkstra2(g,c,s,d) << endl;
  }
}