#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<queue>
#include<map>
#define P pair<int,int>
using namespace std;

struct K {
	int basho, nokori, mincost;
};
bool operator<(K a, K b) {
	return a.mincost > b.mincost;
}
int main() {
	int cost[100][11];//n???????????°????????§m????????????????°????
	int B, c, d, e, f;
	while (scanf("%d%d%d%d%d", &B, &c, &d, &e, &f), B || c || d || e || f) {
		vector<P>a[100]{};
		memset(cost, 0x3f, sizeof(cost));
		e--; f--; cost[e][B] = 0;
		priority_queue<K>Q;
		K g;
		g.basho = e; g.nokori = B; g.mincost = 0;
		Q.push(g);
		for (int h = 0; h < d; h++) {
			int i, j, k;
			scanf("%d%d%d", &i, &j, &k);
			i--; j--;
			a[i].push_back(P(k, j));
			a[j].push_back(P(k, i));
		}
		while (Q.size()) {
			K l = Q.top(); Q.pop();
			int m = l.mincost, n = l.nokori, b = l.basho;
			if (cost[b][n] < m)continue;
			for (P o : a[b]) {
				if (cost[o.second][n] > cost[b][n] + o.first) {
					cost[o.second][n] = cost[b][n] + o.first;
					K xx;
					xx.basho = o.second;
					xx.mincost = cost[o.second][n];
					xx.nokori = n;
					Q.push(xx);
				}
				if (n&&cost[o.second][n-1] > cost[b][n] + o.first / 2) {
					cost[o.second][n - 1] = cost[b][n] + o.first / 2;
					K yy;
					yy.basho = o.second;
					yy.nokori = n - 1;
					yy.mincost = cost[o.second][n - 1];
					Q.push(yy);
				}
			}
		}
		int MINCOST = 1 << 29;
		for (int sss = 0; sss < 11; sss++) {
			MINCOST = min(MINCOST, cost[f][sss]);
		}
		cout << MINCOST << endl;
	}
}