#include <iostream>
#include <vector>
#include <queue>
#include <functional>

constexpr int MAX_N=100,INF=(int)1e9;

struct edge {
	int to,cost;
	edge()=default;
	edge(int _t,int _c) : to(_t),cost(_c) {}
};

struct Node{
	int v,num,cost;
	Node()=default;
	Node(int _v,int _n,int _c) : v(_v),num(_n),cost(_c) {}

	bool operator<(const Node& rhs) const{
		return cost==rhs.cost ? v < rhs.v : cost < rhs.cost; 
	}
	bool operator>(const Node& rhs) const{
		return cost==rhs.cost ? v > rhs.v : cost > rhs.cost;
	}
};

int c,n,m,s,g;

std::vector<edge> G[MAX_N];

int d[11][MAX_N];

int dijkstra() {

	for(int i=0;i<=c;++i){
		for(int j=0;j<n;++j)
			d[i][j]=INF;
	}

	std::priority_queue<Node,std::vector<Node>,std::greater<Node>> que;

	d[c][s]=0;
	que.emplace(s,c,0);

	while(!que.empty()){

		Node node=que.top();
		que.pop();

		int v=node.v;

		if(v==g)
			return d[node.num][g];

		if(node.cost>d[node.num][v])
			continue;

		for(int i=0;i<G[v].size();++i){
			edge e=G[v][i];
			if(node.num==0)
				goto a;
			else{
				if(d[node.num-1][e.to]>d[node.num][v]+e.cost/2){
					d[node.num-1][e.to]=d[node.num][v]+e.cost/2;
					que.emplace(e.to,node.num-1,d[node.num-1][e.to]);
				}
				a:;
				if(d[node.num][e.to]>d[node.num][v]+e.cost){
					d[node.num][e.to]=d[node.num][v]+e.cost;
					que.emplace(e.to,node.num,d[node.num][e.to]);
				}
			}
		}
	}
	return -1;
}

int main() {
	while(1){
		std::cin>>c>>n>>m>>s>>g;
		if(c+n+m+s+g==0)
			return 0;
		--s;
		--g;
		int a,b,f;
		for(int i=0;i<m;++i){
			std::cin>>a>>b>>f;
			--a;
			--b;
			G[a].emplace_back(b,f);
			G[b].emplace_back(a,f);
		}
		int ans=dijkstra();
		std::cout<<ans<<std::endl;
		for(int i=0;i<n;++i)
			G[i].clear();
	}
	return 0;
}