#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int C,N,M,S,D;

class Node
{
	public:
		
		vector<int> to,c;
};

class State
{
	public:

		int p,c,k;
		State(int P, int C, int K)
		{
			p=P; c=C; k=K;
		}

		bool operator<(const State &s) const
		{
			if(c!=s.c) return c>s.c;
			return k>s.k;
		}
};



int main()
{
	while(cin>>C>>N>>M>>S>>D, C||N||M||S||D)
	{
		int v[100][10] = {0};
		Node node[100];

		S--; D--;
		for(int i=0; i<M; i++)
		{
			int x,y,z;
			cin>>x>>y>>z;
			x--; y--;
			node[x].to.push_back(y);
			node[y].to.push_back(x);
			node[x].c.push_back(z);
			node[y].c.push_back(z);
		}

		priority_queue<State>	 q;
		q.push(State(S,0,0));
		while(!q.empty())
		{
			State t=q.top(); q.pop();
			if(t.p==D)
			{
				cout << t.c << endl;
				break;
			}

			if(v[t.p][t.k]) continue;
			v[t.p][t.k] = 1;

			for(int i=0; i<node[t.p].to.size(); i++)
			{
				q.push(State(node[t.p].to[i], t.c+node[t.p].c[i], t.k));
				if(t.k<C)
				{
					q.push(State(node[t.p].to[i], t.c+node[t.p].c[i]/2, t.k+1));
				}
			}
		}


	}
}