#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

#define INF (1 << 26)
#define MAX_V 10000

struct edge{
	int to;
	int cost;
};

typedef pair<int, int> P; // first??????????????¢???second??????????????????

vector<edge> G[MAX_V];
int d[MAX_V];

// ?????????O(|E|log|V|)

void shortest_path(int s, int V){ // V???????????°
	
	priority_queue<P, vector<P>, greater<P> > que;
	
	for(int i = 0; i < V; i++){
		d[i] = INF;
	}
	d[s] = 0;
	
	que.push(P(0, s));
	
	while(!que.empty()){
		
		P p = que.top();
		que.pop();
		
		int v = p.second;
		
		if(d[v] < p.first){
			continue;
		}
		
		for(int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if(d[e.to] > e.cost + d[v]){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		} // ????????????????°???????????????´??°
	}
}

int main(){
	
	int c, n, m, s, g;
	
	while(true){
		cin >> c >> n >> m >> s >> g;
		if(c == 0 && n == 0 && m == 0 && s == 0 && g == 0){
			break;
		}
		int V = n * (c + 1);
		for(int i = 0; i <= V; i++){
			G[i].erase(G[i].begin(), G[i].end());
		}
		for(int i = 0; i < m; i++){
			int a, b, f;
			cin >> a >> b >> f;
			
			int cost = f;
			
			for(int j = 0; j <= c; j++){
				
				int index1 = (a - 1) * (c + 1) + j;
				int index2 = (b - 1) * (c + 1) + j;
				
				edge e1, e2;
				e1.to = index2;
				e2.to = index1;
				e1.cost = cost;
				e2.cost = cost;
				G[index1].push_back(e1);
				G[index2].push_back(e2);
			}
			
			for(int j = 0; j < c; j++){
				
				int index1 = (a - 1) * (c + 1) + j;
				int index2 = (b - 1) * (c + 1) + j + 1;
				
				edge e1;
				e1.to = index2;
				e1.cost = cost / 2;
				G[index1].push_back(e1);
			}
			
			for(int j = 0; j < c; j++){
				
				int index1 = (a - 1) * (c + 1) + j + 1;
				int index2 = (b - 1) * (c + 1) + j;
				
				edge e1;
				e1.to = index1;
				e1.cost = cost / 2;
				G[index2].push_back(e1);
			}
			
		}
		s = (s - 1) * (c + 1);
		g--;
		
		shortest_path(s, V);
		
		int min = INF;
		
		for(int i = 0; i <= c; i++){
			if(d[g * (c + 1) + i] < min){
				min = d[g * (c + 1) + i];
			}
		}
		
		cout << min << endl;
		
	}
	
	return 0;
}