#include <iostream>
#include <vector>
#include <queue>

using namespace std;

struct NODE {
	int now, cost, ticket;
	NODE(int now, int cost, int ticket) : now(now), cost(cost), ticket(ticket) {}
	NODE () {}
};

bool operator < (const NODE &a, const NODE &b)
{
	return a.cost > b.cost;
}

int main(void)
{
	int c, n, m, s, d;
	while (cin >> c >> n >> m >> s >> d, n){
		vector <NODE> edge[150];
		int a, b, f;
		for (int i = 0; i < m; i++){
			cin >> a >> b >> f;
			edge[a].push_back(NODE(b, f, -1));
			edge[b].push_back(NODE(a, f, -1));
		}

		priority_queue <NODE> Q;
		Q.push(NODE(s, 0, c));
		while (Q.size()){
			NODE q = Q.top();
			Q.pop();
			if (q.now == d){
				cout << q.cost << endl;
				break;
			}
			for (int i = 0; i < edge[q.now].size(); i++){
				Q.push(NODE(edge[q.now][i].now, q.cost + edge[q.now][i].cost, q.ticket));
				if (q.ticket){
					Q.push(NODE(edge[q.now][i].now, q.cost + (edge[q.now][i].cost / 2), q.ticket - 1));
				}
			}
		}
	}

	return 0;
}