#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <climits>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

struct Edge
{
	int src, dst;
	int weight;
	Edge(int src, int dst, int weight) : src(src), dst(dst), weight(weight) {}

	bool operator< (const Edge& e)const
	{
		return weight != e.weight ? weight > e.weight :
			src != e.src ? src < e.src : dst < e.dst;
	}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void Dijkstra(const Graph& g, int s, vi& dist, vi& prev)
{
	int n = g.size();
	dist.assign(n, INT_MAX);
	dist[s] = 0;
	prev.assign(n, -1);
	
	priority_queue<Edge> Q;
	Q.push(Edge(-2, s, 0));

	while(!Q.empty()){
		Edge e = Q.top();
		Q.pop();
		if(prev[e.dst] != -1)
			continue;
		prev[e.dst] = e.src;

		rep(i, g[e.dst].size()){
			int pw = e.weight + g[e.dst][i].weight;
			if(dist[g[e.dst][i].dst] > pw){
				dist[g[e.dst][i].dst] = pw;
				Q.push(Edge(g[e.dst][i].src, g[e.dst][i].dst, pw));
			}
		}
	}
}


vi buildPath(const vi& prev, int t)
{
	vi path;
	for(int u = t; u >= 0; u = prev[u])
		path.push_back(u);
	reverse(path.begin(), path.end());
	return path;
}

int main()
{
	int c, n, m, s, d;
	while(scanf("%d%d%d%d%d", &c, &n, &m, &s, &d), c){
		--s; --d;
		Graph g(n*(c+1));
		rep(i, m){
			int a, b, f;
			scanf("%d%d%d", &a, &b, &f);
			--a; --b;

			rep(j, c+1){
				g[j*n+a].push_back(Edge(j*n+a, j*n+b, f));
				g[j*n+b].push_back(Edge(j*n+b, j*n+a, f));
				if(j){
					g[(j-1)*n+a].push_back(Edge((j-1)*n+a, j*n+b, f/2));
					g[(j-1)*n+b].push_back(Edge((j-1)*n+b, j*n+a, f/2));
				}
			}
		}

		vi dist, prev;
		Dijkstra(g, s, dist, prev);

		int ans = INT_MAX;
		rep(j, c+1){
			ans = min(ans, dist[j*n+d]);
		}
		printf("%d\n", ans);
	}

	return 0;
}