#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pp;

const int INF = 1e9;

double EPS = 1e-10;


int c, n, m, s, g;



const int MAX_V = 10000;


//struct edge{ int to, cost; };
struct edge{ int to, cost; edge(int to, int cost):to(to),cost(cost){}};


int V;
vector<edge> G[MAX_V];
map<pii, int> d;


void dijkstra(){
	priority_queue<pp, vector<pp>, greater<pp> > que;
	for(int i = 0; i <= 500000; i++){
		for(int j = 0; j <= 10; j++){
			d[mp(i, -j)] = INF;

		}
	}
	// cout<<"OK"<<endl;
	// cout<<d[mp(2, 0)]<<endl;
	d[mp(s, -c)] = 0;
	que.push(pp(0, pii(s, -c)));

	while(!que.empty()){
		pp p = que.top();
		que.pop();
		pii v = p.second;
		if(d[v] < p.first) continue;
		for(int i = 0; i < G[v.fi].size(); i++){
			edge e = G[v.fi][i];
			//cout<<e.to<<" "<<e.cost<<endl;
			//cout<<" "<<d[mp(e.to, v.se)]<<" "<<d[v] + e.cost<<" "<<e.to<<endl;
			if(d[mp(e.to, v.se)] > d[v] + e.cost){
				//cout<<" "<<v.fi<<" "<<d[mp(e.to, v.se)]<<endl;
				d[mp(e.to, v.se)] = d[v] + e.cost;
				que.push(pp(d[mp(e.to, v.se)],pii(e.to, v.se)));
			}
			if(v.se < 0 && d[mp(e.to, v.se + 1)] > d[v] + e.cost/2){
				//cout<<" "<<v.fi<<" "<<d[mp(e.to, v.se)]<<endl;
				d[mp(e.to, v.se + 1)] = d[v] + e.cost / 2;
				que.push(pp(d[mp(e.to, v.se + 1)],pii(e.to, v.se + 1)));
			}
		}
	}
}


int main(){
	int a, b, f;
	int ans;
	while(cin>>c>>n>>m>>s>>g){
		if(c == 0 && n == 0 && m == 0 && s == 0 && g == 0) break;
		s--; g--;
		for(int i = 0; i < MAX_V; i++) G[i].clear();
		for(int i = 0; i < m; i++){
			cin>>a>>b>>f;
			f/=10;
			a--; b--;
			G[a].push_back(edge(b, f));
			G[b].push_back(edge(a, f));
		}
		dijkstra();
		ans = INF;
		for(int i = -10; i <= 0; i++){
			ans = min(ans, d[mp(g, i)]);
		}
		//cout<<"   "<<d[mp(2,0)]<<endl;
		cout<<ans*10<<endl;
	}
	
}