#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 29;
const double EPS = 1e-10;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
#define repD(i, n) for(int i = n; i >= 0; i--)

int cost[200][20];
vector<P> G[200];// to cost;

int main(){
	int c, n, m, s, d;
	int a, b, money;
	while(cin >> c  >> n >> m >> s >> d && (c || n || m || s || d)){
		rep(i, 200) G[i].clear();
		fill(&cost[0][0], &cost[199][19] + 1, INF);
		rep(i, m){
			cin >> a >> b >> money;
			G[a].push_back(P(b, money));
			G[b].push_back(P(a, money));
		}

		cost[s][c] = 0;
		priority_queue<PP, vector<PP>, greater<PP> > que;
		que.push(PP(0, P(s, c)));
		while(!que.empty()){
			PP pp = que.top();
			que.pop();
			int cos = pp.first;
			int pos = pp.second.first;
			int num = pp.second.second;
			if(pos == d){
				cout << cos << endl;
				break;
			}

			if(cos > cost[pos][num]) continue;
			rep(i,(int)G[pos].size()){
				int v = G[pos][i].first;
				int fee = G[pos][i].second;
				if(cost[v][num] > cos + fee){
					cost[v][num] = cos + fee;
					que.push(PP(cost[v][num], P(v, num)));
				}
				if(num > 0 && cost[v][num-1] > cos + fee / 2){
					cost[v][num-1] = cos + fee / 2;
					que.push(PP(cost[v][num-1], P(v, num-1)));
				}
			}
		}
	}
	return 0;
}