#include <iostream>
#include <functional>
#include <queue>
using namespace std;

const int INF = 10000000;

typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef priority_queue<PP, vector<PP>, greater<PP> > Q;

int C, N, M, S, D;
int m[100][100];
int u[11][100];

bool input() {
  cin >> C >> N >> M >> S >> D;
  if (!C && !N && !M && !S && !D) {
    return false;
  }
  --S, --D;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      m[i][j] = INF;
    }
    m[i][i] = 0;
  }
  for (int i = 0; i < M; ++i) {
    int a, b, f;
    cin >> a >> b >> f;
    --a, --b;
    m[a][b] = f;
    m[b][a] = f;
  }
  return true;
}

void solve() {
  for (int k = 0; k <= C; ++k) {
    for (int i = 0; i < N; ++i) {
      u[k][i] = INF;
    }
  }
  Q q;
  q.push(PP(0, P(0, S)));
  int ans = INF;
  while (!q.empty()) {
    PP pp = q.top();
    q.pop();
    int f = pp.first;
    P p = pp.second;
    int k = p.first;
    int l = p.second;
    if (l == D) {
      ans = f;
      break;
    }
    if (u[k][l] != INF) {
      continue;
    }
    u[k][l] = f;
    for (int i = 0; i < N; ++i) {
      if (l == i || m[l][i] == INF) {
        continue;
      }
      q.push(PP(f + m[l][i], P(k, i)));
      if (k < C) {
        q.push(PP(f + m[l][i]/2, P(k + 1, i)));
      }
    }
  }
  cout << ans << endl;
}

int main() {
  while (input()) {
    solve();
  }
  return 0;
}