#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef pair<int, int> P;
typedef long long ll;

const int INF = 1 << 30;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

int n, m, res;

#define debug(a, b, c) for(int i = 0; i < b; i++){for(int j = 0; j < c; j++){printf("%12d", a[i][j]);}puts("");}puts("-----------------------------------------");

int main()
{
	int wk, tk, c;
	int disc, city, line, start, goal;
	int route[512][512], cost[512][16];
	bool used[512];
	while(cin >> disc >> city >> line >> start >> goal)
	{
		if(!disc && !city && !line && !start && !goal) break;

		start--, goal--;
		for(int i = 0; i < city; i++)
		{
			fill(route[i], route[i] + city, INF);
			fill(cost[i], cost[i] + city, INF);
		}

		for(int i = 0; i < line; i++)
		{
			cin >> wk >> tk >> c;
			route[wk-1][tk-1] = c;
			route[tk-1][wk-1] = c;
		}

		for(int m = 0; m <= disc; m++)
		{
			cost[start][m] = 0;
			//debug(cost, disc, city);
			fill(used, used + city, false);

			while(true)
			{
				int v = -1;
				for(int i = 0; i < city; i++)
				{
					if(!used[i] && (v == -1 || cost[i][m] < cost[v][m])) v = i;
				}

				if(v == -1) break;

				used[v] = true;

				for(int i = 0; i < city; i++)
				{
					if(m == 0)	
						cost[i][m] = min(cost[i][m], cost[v][m] + route[v][i]);
					else
						cost[i][m] = min(cost[v][m - 1] + route[v][i] / 2, min(cost[i][m], cost[v][m] + route[v][i]));
				}
			}
		}
		cout <<	cost[goal][disc] << endl;

	}
}