//1.includes
#include<iostream>
#include<algorithm>
#include<queue>
#include<tuple>
#include<functional>
#include<vector>
using namespace std;

//2.defines
#define INF 1000000000000000000LL//10^18
#define MAX_N 1000
#define MAX_C 100
#define BLACK 2
#define GRAY 1
#define WHITE 0

//3.variables
priority_queue<tuple<long long, long long, long long>, vector<tuple<long long, long long, long long>>, greater<tuple<long long, long long, long long>>>Q;
long long dist[MAX_N][MAX_C];
long long color[MAX_N][MAX_C];
vector<pair<long long, long long>>X[MAX_N];
long long C, N, M, S, D, A, B, G;

//4.functions
void _memset() {
	for (int i = 0; i < MAX_N; i++) {
		for (int j = 0; j < MAX_C; j++) {
			dist[i][j] = 0;
			color[i][j] = WHITE;
		}
	}
	for (int i = 0; i < MAX_N; i++) {
		X[i].clear();
	}
	while (!Q.empty()) {
		Q.pop();
	}
}

long long dijkstra(long long s, long long t, long long u) {
	for (int i = 0; i < MAX_N; i++) {
		for (int j = 0; j < MAX_C; j++) {
			dist[i][j] = INF;
			color[i][j] = WHITE;
		}
	}
	Q.push(make_tuple(0, 0, s));
	dist[s][0] = 0;
	color[s][0] = GRAY;
	while (!Q.empty()) {
		tuple<long long, long long, long long> tup = Q.top();
		Q.pop();
		long long a1 = get<0>(tup);
		long long a2 = get<1>(tup);
		long long a3 = get<2>(tup);
		color[a3][a2] = BLACK;
		for (int i = 0; i < X[a3].size(); i++) {
			long long a4 = X[a3][i].first;
			long long a5 = X[a3][i].second;
			bool ok = true;
			if (color[a4][a2] == BLACK) { ok = false; }
			if (ok == true && a1 + a5 < dist[a4][a2]) {
				dist[a4][a2] = a1 + a5;
				color[a4][a2] = GRAY;
				Q.push(make_tuple(dist[a4][a2], a2, a4));
			}
			ok = true;
			if (color[a4][a2 + 1] == BLACK) { ok = false; }
			if (a2 + 1 > u) { ok = false; }
			if (ok == true && a1 + a5 / 2 < dist[a4][a2 + 1]) {
				dist[a4][a2 + 1] = a1 + a5 / 2;
				color[a4][a2 + 1] = GRAY;
				Q.push(make_tuple(dist[a4][a2 + 1], a2 + 1, a4));
			}
		}
	}
	long long minx = INF;
	for (int i = 0; i <= u; i++) {
		minx = min(minx, dist[t][i]);
	}
	return minx;
}

int main() {
	while (true) {
		_memset();
		cin >> C >> N >> M >> S >> D;
		if (C == 0 && N == 0 && M == 0 && S == 0 && D == 0) {
			break; //C=number of ticket
		}
		for (int i = 0; i < M; i++) {
			cin >> A >> B >> G;
			X[A].push_back(make_pair(B, G));
			X[B].push_back(make_pair(A, G));
		}
		cout << dijkstra(S, D, C) << endl;
	}
	return 0;
}