#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(void) {
	while(true) {
		ll c, n, m, s, d;
		cin>>c>>n>>m>>s>>d;
		if(c == 0 && n == 0 && m == 0 && s == 0 && d == 0) break;
		--s;
		--d;
		vector<vector<P> > p(n);
		vector<vector<ll> > dir(n, vector<ll>(c + 1, INF * INF));
		REP(i, m) {
			int a, b, f;
			cin>>a>>b>>f;
			--a;
			--b;
			p[a].pb(P(b, f));
			p[b].pb(P(a, f));
		}
		priority_queue<pair<P, ll> > que;
		que.push(pair<P, ll>(P(0, s), c));
		dir[s][c] = 0;
		while(!que.empty()) {
			pair<P, ll> np = que.top();
			que.pop();
			if(dir[np.first.second][np.second] != np.first.first) continue;
			REP(i, p[np.first.second].size()) {
				if(dir[p[np.first.second][i].first][np.second] > dir[np.first.second][np.second] + p[np.first.second][i].second) {
					dir[p[np.first.second][i].first][np.second] = dir[np.first.second][np.second] + p[np.first.second][i].second;
					que.push(pair<P, ll>(P(dir[p[np.first.second][i].first][np.second], p[np.first.second][i].first), np.second));
				}
				if(np.second > 0 && dir[p[np.first.second][i].first][np.second - 1] > dir[np.first.second][np.second] + p[np.first.second][i].second / 2) {
					dir[p[np.first.second][i].first][np.second - 1] = dir[np.first.second][np.second] + p[np.first.second][i].second / 2;
					que.push(pair<P, ll>(P(dir[p[np.first.second][i].first][np.second - 1], p[np.first.second][i].first), np.second - 1));
				}
			}
		}
		ll res = INF * INF;
		REP(i, c + 1) {
			res = min(res, dir[d][i]);
		}
		cout<<res<<endl;
	}
}