#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

int minimum,num_ticket,num_town,m,start,goal,costTable[101][101];

class PQ{
public:
	PQ(){
		array = new int[100];
		n = 0;
	}
	void push(int arg_info){
		array[n] = arg_info;
		int tmp = n;
		while(tmp != 0 && array[tmp] < array[(tmp-1)/2]){
			swap(array[tmp], array[(tmp-1)/2]);
			tmp = (tmp-1)/2;
		}
		n++;
	}

	bool empty(){
		return n == 0;
	}

	int get(int i){
		return array[i];
	}

	int pop(){
		int ret = array[0];
		n--;
		swap(array[0],array[n]);
		int tmp = 0;
		while(2*tmp+1 <= n-1){
			if(2*tmp+2 <= n-1){
				if(array[2*tmp+2] < array[tmp] && array[2*tmp+2] <= array[2*tmp+1]){
					swap(array[2*tmp+2],array[tmp]);
					tmp = 2*tmp+2;
				}else if(array[2*tmp+1] < array[tmp] && array[2*tmp+1] <= array[2*tmp+2]){
					swap(array[2*tmp+1],array[tmp]);
					tmp = 2*tmp+1;
				}else{
					break;
				}
			}else{
				if(array[tmp] > array[2*tmp+1]){
					swap(array[tmp],array[2*tmp+1]);
					tmp = 2*tmp+1;
				}else{
					break;
				}
			}
		}
		return ret;
	}

private:
	int* array;
	int n;
};


struct Info{
	Info(){
		for(int i = 1; i <= num_town; i++){
			visited[i] = false;
		}
		current_town = 0;
		index = 0;
	}
	bool visited[101];
	int current_town,index;
	PQ Q;
};

void func(Info info){
	if(info.current_town == goal){

		int sum = 0;

		if(num_ticket >= info.index){
			while(!info.Q.empty()){
				sum += info.Q.pop();
			}
			sum /= 2;
			minimum = min(minimum,sum);
		}else{

			int count = 0,tmp;
			while(!info.Q.empty()){
				tmp = info.Q.pop();
				if(count < num_ticket){
					sum += tmp/2;
				}else{
					sum += tmp;
				}
				count++;
			}
			minimum = min(minimum,sum);
		}
		return;
	}

	for(int i = 1; i <= num_town; i++){
		if(info.visited[i] == false && costTable[info.current_town][i] != -1){

			Info new_info;

			for(int k = 1; k <= num_town; k++){
				new_info.visited[k] = info.visited[k];
			}
			new_info.visited[i] = true;
			new_info.current_town = i;
			new_info.index = info.index+1;

			for(int k = 0; k < info.index; k++){
				new_info.Q.push(info.Q.get(k));
			}

			new_info.Q.push(costTable[info.current_town][i]);
			func(new_info);
		}
	}
}

int main(){

	int from,to,fee;

	while(true){
		scanf("%d %d %d %d %d",&num_ticket,&num_town,&m,&start,&goal);
		if(num_ticket == 0 && num_town == 0 && m == 0 && start == 0 && goal == 0)break;

		minimum = 2000000000;

		for(int i = 1; i <= num_town; i++){
			for(int k = 1; k <= num_town; k++)costTable[i][k] = -1;
		}

		for(int i = 0; i < m; i++){
			scanf("%d %d %d",&from,&to,&fee);
			costTable[from][to] = fee;
			costTable[to][from] = fee;
		}

		Info info;

		info.current_town = start;
		info.visited[start] = true;

		func(info);

		printf("%d\n",minimum);
	}


	return 0;
}