#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>

using namespace std;

struct Node
{
	int num, cost, ticket;
	Node(int n, int c, int t)
	{
		num = n;cost = c; ticket = t;
	}

	bool operator < (const Node &o) const
	{
		return cost > o.cost;
	}
};

const int MAX_NODE_ID = 1024;
const int MAX_TICKET = 1024;
bool visited[MAX_NODE_ID][MAX_TICKET];

int c, n, m, s, d;

#define MAX 50000
int map[101][101];

int main()
{
	while (true)
	{
		cin >> c >> n >> m >> s >> d;
		if (c == 0 && n == 0 && m == 0 && s == 0 && d == 0) break;
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				map[i][j] = MAX;
		for (int i = 0; i < m; i++)
		{
			int a, b, f;
			cin >> a >> b >> f;
			map[a][b] = map[b][a] = f;
		}
		for (int i = 0; i < MAX_NODE_ID; i++)
			for (int j = 0; j < MAX_TICKET; j++)
				visited[i][j] = false;
		priority_queue<Node> que;
		int minimum = MAX;
		que.push(Node(s, 0, c));
		while (!que.empty())
		{
			Node nod = que.top();
			que.pop();
			if (nod.num == d)
			{
				//S[
				minimum = min<int>(minimum, nod.cost);
			}
			else
			{
				for (int i = 1; i <= n; i++)
				{
					if (map[nod.num][i] < MAX && !visited[nod.num][nod.ticket])
					{
						que.push(Node(i, nod.cost + map[nod.num][i], nod.ticket));
						if (nod.ticket > 0)
						{
							que.push(Node(i, nod.cost + map[nod.num][i] / 2, nod.ticket - 1));
						}
					}
				}
			}
			visited[nod.num][nod.ticket] = true;
		}
		cout <<	minimum << endl;
	}
	return 0;
}