#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
};

/** Problem0212 : Highway Express Bus **/
struct edge{
	int from, to, cost;
	edge(int f, int t, int c):from(f), to(t), cost(c){}
	edge(){}
};
vector<edge> G;

int main()
{
	int C, N, M, S, D;
	while (cin>>C>>N>>M>>S>>D, C) {
		S--, D--;
		G.clear();
		
		rep(i, M) {
			int a, b, f;
			cin>>a>>b>>f;
			a--, b--;
			G.push_back(edge(a, b, f));
			G.push_back(edge(b, a, f));
		}
		
		int d[100][11];
		fill(d[0], d[0]+1000, INF);
		for (int i=0; i<C+1; i++) d[S][i]=0;
		
		while (true) {
			bool update=false;
			
			for (int i=0; i<G.size(); i++) {
				edge e = G[i];
				for (int j=0; j<=C; j++) {
					if (d[e.to][j] > d[e.from][j] + e.cost) {
						d[e.to][j] = d[e.from][j] + e.cost;
						update = true;
					}
					
					
					if (j<=C) {
						if (d[e.to][j+1] > d[e.from][j]+e.cost/2) {
							d[e.to][j+1] = d[e.from][j]+e.cost/2;
							update = true;
						}
					}
				}
			}
			
			if (!update) break;
		}
		
		int ans = INF;
		for (int i=0; i<C+1; i++) {
			ans = min(ans, d[D][i]);
		}
		cout << ans << endl;
	}
}