#include <iostream>
#include <queue>
#include <functional>
#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;
	vector<int> visited(n, INF);
	q.push(make_pair(make_pair(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();
		visited[curr]  = c;
		if(curr == d) return c;
        if(c > visited[curr]) continue;
		for(int i(0);i < n;++i){
			if(edge[curr][i] != INF){
				int nc = c + edge[curr][i];
				int next = i;
                q.push(make_pair(make_pair(nc, next), dc));
				nc = c + edge[curr][i] / 2;
				if(dc > 0){
					q.push(make_pair(make_pair(nc, next), dc - 1));
				}
			}
		}
	}
	return -1;
}

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(0);j < N;++j){
				edge[i][j] = 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;
	}
}