/*
g£_CNXg
*/
#include<iostream>
#include<queue>
#include<map>
#define INF 10000000
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int> p;
typedef pair<int,p> P;
//P(cost,p(node,ticket))
struct edge{
	int cost,to;
};
int nticket,nnode,nedge,start,goal,d[11][101];
vector<edge> v[101];
void dijkstra(){
	int nowticket,nowplace,nowsum;
	priority_queue<P,vector<P>,greater<P> > que;
	que.push(P(0,p(start,nticket)));
	while(!que.empty()){
		P now=que.top();
		que.pop();
		
		nowsum=now.first;
		nowplace=now.second.first;
		nowticket=now.second.second;
		
		if(d[nowticket][nowplace]<nowsum)
			continue;
		rep(i,(int)v[nowplace].size()){
			edge e=v[nowplace][i];
			if(nowticket>0){
				if(d[nowticket-1][e.to]>e.cost/2+nowsum){
				d[nowticket-1][e.to]=e.cost/2+nowsum;
				que.push(P(d[nowticket-1][e.to],p(e.to,nowticket-1)));
				}
			}
			if(d[nowticket][e.to]>e.cost+nowsum){
				d[nowticket][e.to]=e.cost+nowsum;
				que.push(P(d[nowticket][e.to],p(e.to,nowticket)));
			}
		}
	}
}
void input(){
	int a,b,f;
	rep(i,nedge){
			cin>>a>>b>>f;
			a--;b--;
			edge c;
			c.cost=f;
			c.to=b;v[a].push_back(c);
			c.to=a;v[b].push_back(c);
		}
}
void init(){
	rep(i,nticket+1)
		rep(j,nnode){
			if(j==start)
			d[i][j]=0;
			else
			d[i][j]=INF;
	}
}
int main(){
	//d[ticket][node]=Å­ïp
	while(cin>>nticket>>nnode>>nedge>>start>>goal,nticket||nnode||nedge||start||goal){
		start--;goal--;
		//ticket:`Pbg
		//nnode:nodeÌ
		//nedge:edgeÌ
		//start¨goal
		input();
		init();
		dijkstra();
		int ans=INF;
		for(int i=0;i<nticket+1;i++)
		ans=min(d[i][goal],ans);
		cout<<ans<<endl;
		for(int i=0;i<nnode;i++)
		v[i].clear();
	}
	return 0;
}