#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define REV(s) (s).rbegin(), (s).rend()
#define MEMSET(v, s) memset(v, s, sizeof(v));
#define MP make_pair
#define X first
#define Y second

using namespace std;

const double EPS = 1e-8;

typedef pair<int, int> P;
typedef long long ll;

template<class T> inline T sq(T a){return a*a;}
template<class T> T gcd(T m, T n){return n?gcd(n, m%n):m;}

int dp[101][11];

vector<P> G[101];

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

int main(){
	int c, n, m, s, d;
	while(cin >> c >> n >> m >> s >> d, c|n|m|s|d){
		rep(i, 101) G[i].clear();
		s--, d--;
		rep(i, m){
			int a, b, f;
			cin >> a >> b >> f;
			a--, b--;
			G[a].push_back(MP(b, f));
			G[b].push_back(MP(a, f));
		}
		rep(i, 101) rep(j, 11) dp[i][j] = 1<<29;

		priority_queue<state> q;
		q.push(state(s, 0, c));
		int ans = -1;
		while(!q.empty()){
			state st = q.top();
			q.pop();

			if(dp[st.p][st.t] < st.c) continue;
			if(st.p == d) break;

			rep(i, G[st.p].size()){
				state next = st;
				next.p = G[st.p][i].first;
				next.c += G[st.p][i].second;
				if(next.c < dp[next.p][next.t]){
					dp[next.p][next.t] = next.c;
					q.push(next);
				}
				if(next.t > 0){
					next.c -= G[st.p][i].second/2;
					next.t--;
					if(next.c < dp[next.p][next.t]){
						dp[next.p][next.t] = next.c;
						q.push(next);
					}
				}
			}
		}

		cout << *min_element(dp[d], dp[d]+11) << endl;
	}

	return 0;
}