#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

struct state {
	int p, t, c;
	state(int p, int t, int c) : p(p), t(t), c(c) {};
	bool operator<(const state &o)const {
		return o.c<c;
	}
};

int main() {
	int c, n, m, s, d;
	while(cin >> c >> n >> m >> s >> d, c) {
		vvi dist(n, vi(n, INF));
		int a, b, f;
		REP(i, m) {
			cin >> a >> b >> f;
			dist[a-1][b-1] = dist[b-1][a-1] = f;
		}
	

		priority_queue<state> Q;
		vvi cost(n, vi(c+1, INF));
		Q.push(state(s-1, 0, 0));
		cost[s-1][0] = 0;
		while(!Q.empty()) {
			state st = Q.top();
			Q.pop();

			if(st.p == d-1) {
				continue;
			}

			REP(i, n) {
				if(st.p != i) {
					if(st.t < c) {
						int nc = st.c + dist[st.p][i]/2;
						if(nc < cost[i][st.t+1]) {
							cost[i][st.t+1] = nc;
							Q.push(state(i, st.t+1, nc));
						}
					}
					int nc = st.c + dist[st.p][i];
					if(nc < cost[i][st.t]) {
						cost[i][st.t] = nc;
						Q.push(state(i, st.t, nc));
					}
				}
			}
		}

		int ans = INF;
		REP(i, c+1) {
			ans = min(ans, cost[d-1][i]);
		}

		cout << ans << endl;
	}
	return 0;
}