#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

#define INF 1000000000
#define MAX_N 100

class CDij{
public:
	int min_c;
	vector<int> vec;
};

int n;
int c,m;
int s,d;

queue<int> q;

int cost[MAX_N+1][MAX_N+1];

CDij dp[MAX_N+1];//sからiに行くまでの最小運賃

vector<int> ans;

int main(){

	while(1){
		cin >> c >> n >> m >> s >> d;

		if(c+n+m+s+d==0) break;

		for(int i=0;i<=n;i++){
			for(int j=0;j<=n;j++){
				cost[i][j] = -1;
			}
		}

		for(int i=1;i<=n;i++){
			dp[i].min_c = INF;
			for(int j=0;j<dp[i].vec.size();j++){
				dp[i].vec.pop_back();
			}
		}

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

		q.push(s);
		dp[s].min_c = 0;
		dp[s].vec.push_back(s);

		while(!q.empty()){
			int now = q.front();
			q.pop();

			for(int i=1;i<=n;i++){
				if(cost[now][i] != -1){
					vector<int> root;
					root = dp[now].vec;
					root.push_back(i);

					vector<int> vec;

					int size = root.size()-1;

					for(int j=0;j<size;j++){
						vec.push_back( cost[root[j]][root[j+1]] );
					}
					sort(vec.begin(),vec.end(),greater<int>());

					size = vec.size();
					for(int j=0;j<min(c,size);j++){
						vec[j] /= 2;
					}

					int sum = 0;
					size = vec.size();

					for(int j=0;j<size;j++){
						sum+=vec[j];
					}

					if(sum < dp[i].min_c){
						dp[i].min_c = sum;
						dp[i].vec = root;
						q.push(i);
					}
				}
			}
	
		}

		ans.push_back(dp[d].min_c);

	}

	for(int i=0;i<ans.size();i++){
		cout << ans[i] << endl;
	}


	return 0;
}