#include <iostream>
#include <queue>
#include <functional>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
using namespace std;

typedef pair<int, int> P;
typedef pair<P, int> State;

const int N = 100, INF = 1e8;

int edge[N][N];

int dijkstra(int n, int s, int d, int c){
	priority_queue<State, vector<State>, greater<State> > q;
	int visited[N][11] = {}, res;
	for(int i(0);i < N;++i){
		for(int j(0);j <= 10;++j){
			visited[i][j] = INF;
		}
	}
	q.push(State(P(0, s), c));
	while(!q.empty()){
		int c = q.top().first.first;
		int curr = q.top().first.second;
		int dc = q.top().second;
		q.pop();
        if(c > visited[curr][dc]) continue;
		for(int i(0);i < n;++i){
			if(edge[curr][i] != INF){
				int nc = c + edge[curr][i];
				int next = i;
				if(visited[next][dc] > nc){
                    visited[next][dc] = nc;
					q.push(State(P(nc, next), dc));
				}
				nc = c + edge[curr][next] / 2;
				if(dc > 0 && visited[next][dc - 1] > nc){
                    visited[next][dc - 1] = nc;
					q.push(State(P(nc, next), dc - 1));
				}
			}
		}
	}
	res = INF;
	for(int i(0);i < n;++i){
		res = min(res, visited[d][i]);
	}
    return res;
}

int main(){
	int c, n, m, s, d, a, b, f;
	while(cin >> c >> n >> m >> s >> d, c && n && m && s && d){
		for(int i(0);i < N;++i){
			for(int j(i);j < N;++j){
				edge[i][j] = edge[j][i] = INF;
			}
		}
		--s;
		--d;
		for(int i(0);i < m;++i){
			cin >> a >> b >> f;
			--a;
			--b;
			edge[a][b] = edge[b][a] = f;
		}
        cout << dijkstra(n, s, d, c) << endl;
	}
    return 0;
}