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

const int INF = 1e+9;

struct State {
  int f, v, tickets;
  State(int f, int v, int t) : f(f), v(v), tickets(t) {}
};

struct Node {
  int to, c;
  Node(int to, int c) : to(to), c(c) {}
};

bool operator > (const State& lhs, const State& rhs){
  if(lhs.f == rhs.f)
    return (lhs.v == rhs.v) ? lhs.tickets > rhs.tickets : lhs.v > rhs.v;
  else
    return lhs.f > rhs.f;
}

int N, M, C, d[101][11];
vector<Node> G[101];

void dijkstra(int s){
  for(int i = 0; i <= N; ++i)
    for(int j = 0; j <= C; ++j)
      d[i][j] = INF;
  for(int i = 0; i <= C; ++i)
    d[s][i] = 0;
  priority_queue<State, vector<State>, greater<State> > que;
  que.push(State(0, s, C));
  while(!que.empty()){
    State st = que.top();
    que.pop();
    if(d[st.v][st.tickets] < st.f)
      continue;
    for(int i = 0; i < G[st.v].size(); ++i){
      Node n = G[st.v][i];
      if(d[n.to][st.tickets] > st.f + n.c){
	d[n.to][st.tickets] = st.f + n.c;
	que.push(State(d[n.to][st.tickets], n.to, st.tickets));
      }
      if(d[n.to][st.tickets - 1] > st.f + n.c / 2){
	d[n.to][st.tickets - 1] = st.f + n.c / 2;
	que.push(State(d[n.to][st.tickets - 1], n.to, st.tickets - 1));
      }
    }
  }
}


int main() {
  int s, e, a, b, f;
  while(cin >> C >> N >> M >> s >> e && (N || M || C || s || e)){
    for(int i = 0; i <= 100; ++i)
      G[i].clear();
    for(int i = 0; i < M; ++i){
      scanf("%d%d%d", &a, &b, &f);
      G[a].push_back(Node(b, f));
      G[b].push_back(Node(a, f));
    }
    dijkstra(s);
    int ans = INF;
    for(int i = 0; i <= C; ++i)
      ans = min(ans, d[e][i]);
    cout << ans << endl;
  }
  return 0;
}