#include <iostream>
#include <algorithm>

using namespace std;

const int NODE = 100;
const int TICKET = 10 + 1;
const int INF = 1 << 20;	// 1048576

int E[NODE][NODE];
int cost[TICKET][NODE];
bool used[NODE];

void dijkstra ( int C, int N, int S )
{
	for (int c = 0; c <= C; ++c)
	{
		for (int i = 0; i < N; ++i)
			used[i] = false;
		
		cost[c][S] = 0;
		
		while ( 1 )
		{
			int v = -1;
			for (int i = 0; i < N; ++i)
				if ( !used[i] && ( v == -1 || cost[c][v] > cost[c][i] ))
					v = i;
			if ( v == -1 ) break;
			
			used[v] = true;
			
			if ( c )
				for (int i = 0; i < N; ++i)
				{
					cost[c][i] = min(cost[c][i], min(cost[c][v] + E[v][i] , cost[c-1][v] + E[v][i] / 2));
				}
			else
				for (int i = 0; i < N; ++i)
				{
					cost[c][i] = min(cost[c][i], cost[c][v] + E[v][i]);
				}
		}
	}
}

void init ( void )
{
	for (int i = 0; i < NODE; ++i)
	{
		for (int j = 0; j < NODE; ++j)
			E[i][j] = INF;
		for (int j = 0; j < TICKET; ++j)
			cost[j][i] = INF;
	}	
}

int main ( void )
{
	int c, n, m, s, d;
	
	while ( cin >> c >> n >> m >> s >> d,
		c | n | m | s | d )
	{
		init();
		
		for (int i = 0, a, b, f; i < m; i += 1)
		{
			cin >> a >> b >> f;
			E[a-1][b-1] = E[b-1][a-1] = f;
		}
		
		dijkstra( c, n, s-1 );
		
		cout << cost[c][d-1] << endl;
	}
	return 0;
}