#include <iostream>
#include <queue>
#include <cstring>
using namespace std;
int c, n, m, s, d;

int field[101][101];
int visited[11][101];

int main () {
	while (cin >> c >> n >> m >> s >> d, c || n || m || s || d) {
		memset(field, 0, sizeof(field));
		memset(visited, 0, sizeof(visited));
		for (int i = 0; i < m; i++) {
			int a, b, f;
			cin >> a >> b >> f;
			field[a][b] = field[b][a] = f / 10;
		}
		priority_queue<pair<int, pair<int, int> >, vector<pair<int, pair<int, int> > >, greater<pair<int, pair<int, int> > > > q;
		q.push(make_pair(0, make_pair(c, s)));
		while (!q.empty()) {
			pair<int, pair<int, int> > current = q.top();
			q.pop();
			if (current.second.second == d) {
				cout << current.first * 10 << endl;
				break;
			}
			visited[current.second.first][current.second.second] = 1;
			for (int i = 1; i <= n; i++) {
				if (field[current.second.second][i] > 0) {
					if (!visited[current.second.first][i]) {
						q.push(make_pair(current.first + field[current.second.second][i], make_pair(current.second.first, i)));
					}
					if (current.second.first > 0 && !visited[current.second.first - 1][i]) {
						q.push(make_pair(current.first + field[current.second.second][i] / 2, make_pair(current.second.first - 1, i)));
					}
				}
			}
		}
	}
	return 0;
}