#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string.h>

#define X first
#define Y second
#define MP make_pair
typedef long long ll;
using namespace std;
const int MAX = 101;

int mindis[11][101];
bool used[11][101];
int eCost[101][101];

int main(){
	int c, n, m, s, d;
	while(cin >> c >> n >> m >> s >> d && c|n|m|s|d){
		for(int i = 0; i < 11; i++){ 
			fill(mindis[i], mindis[i]+MAX, 1<<29);
			fill(used[i], used[i]+MAX, false);
		}
		for(int i = 0; i < MAX; i++) fill(eCost[i], eCost[i]+MAX, 1<<29);

		for(int i = 0; i < m; i++){
			int a, b, cost;
			cin >> a >> b >> cost;
			eCost[a][b] = cost;
			eCost[b][a] = cost;
		}

		mindis[0][s] = 0;

		while(1){
			//firstが使った割引チケット数、secondが頂点
			pair<int, int> v(-1, -1);
			int mostmin = 1<<29;
			for(int i = 0; i <= c; i++){
				for(int j = 1; j <= n; j++){
					if(!used[i][j] && ((v.first == -1 || v.second == -1) || mindis[i][j] < mostmin)){
						v.first = i;
						v.second = j;
						mostmin = mindis[i][j];
					}
				}
			}

			if(v.first == c && v.second == n) break;
			used[v.first][v.second] = true;


			for(int i = 1; i <= n; i++){
				if(v.first<c){
					if(mindis[v.first+1][i] > mindis[v.first][v.second]+(eCost[v.second][i]/2)){
						mindis[v.first+1][i] = mindis[v.first][v.second]+(eCost[v.second][i]/2);
					}
				}
				if(mindis[v.first][i] > mindis[v.first][v.second]+eCost[v.second][i]){
					mindis[v.first][i] = mindis[v.first][v.second]+eCost[v.second][i];
				}
			}
		}

		int minc = 1<<29;
		for(int i = 0; i <= c; i++){
			minc = minc>mindis[i][d]?mindis[i][d]:minc;
		}

		cout << minc << endl;
	}
	return 0;
}