// 2010/12/29 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int c, n, m, s, d;
		cin >> c >> n >> m >> s >> d;
		if(c==0&&n==0&&m==0&&s==0&&d==0)
			break;

		int wgt[102][102];
		int hlf[102][102];
		for(int i=1; i<=n; i++)
			for(int j=1; j<=n; j++)
				if(i==j){
					wgt[i][j] = 0;
					hlf[i][j] = 20000;
				}
				else{
					wgt[i][j] = 20000;
					hlf[i][j] = 20000;
				}

		for(int i=0; i<m; i++){
			int a, b, f;
			cin >> a >> b >> f;
			wgt[a][b] = f;
			wgt[b][a] = f;
			hlf[a][b] = f/2;
			hlf[b][a] = f/2;
		}

		int djk[12][102];
		bool flg[12][102];
		for(int i=1; i<=n; i++){
			djk[c][i] = wgt[s][i];
			flg[c][i] = false;
			djk[c-1][i] = hlf[s][i];
			flg[c-1][i] = false;
		}
		for(int j=c-2; j>=0; j--)
			for(int i=1; i<=n; i++){
				djk[j][i] = 20000;
				flg[j][i] = false;
			}

		while(true){
			int j_min = 11;
			int i_min = 0;
			int w_min = 2000000;
			for(int j=0; j<=c; j++)
				for(int i=1; i<=n; i++)
					if((!flg[j][i])&&(djk[j][i]<w_min)){
						j_min = j;
						i_min = i;
						w_min = djk[j][i];
					}

			flg[j_min][i_min] = true;
			if(i_min==d){
				cout << djk[j_min][i_min] << endl;
				break;
			}

			for(int j=0; j<=c; j++)
				for(int i=1; i<=n; i++)
					if(!flg[j][i])
						if(wgt[i_min][i]!=20000)
							if(djk[j][i]>djk[j][i_min]+wgt[i_min][i])
								djk[j][i] = djk[j][i_min]+wgt[i_min][i];

			for(int j=1; j<=c; j++)
				for(int i=1; i<=n; i++)
					if(!flg[j-1][i])
						if(hlf[i_min][i]!=20000)
							if(djk[j-1][i]>djk[j][i_min]+hlf[i_min][i])
								djk[j-1][i] = djk[j][i_min]+hlf[i_min][i];
		}
	}

	return 0;
}