#include<bits/stdc++.h>
#define MAX_V 101
using namespace std;

struct edge { 
  int to, cost;
  edge(){}
  edge(int to,int cost):to(to),cost(cost){};
};
typedef pair<int ,int> P;
const int INF = 1 << 30;
int V; //ノードの数
vector<edge> Graph[MAX_V];
int min_cost[11][MAX_V];

int c,m,s,d;
void Dijkstra(int s,int chip){ // s:スタートからの最小コストをmin_costに設定
  priority_queue<P,vector< P >, greater<P> > que;
  fill(min_cost[chip],min_cost[chip] + V,INF);
  min_cost[chip][s] = 0;
  que.push(P(0,s));
  
  while(!que.empty()){
    P p = que.top();que.pop();
    int now = p.second;
    int cost = p.first;
    if(min_cost[chip][now] < cost) continue;
    
    for(int i = 0; i < Graph[now].size(); i++){
      edge e = Graph[now][i];
      int a;
      if(chip == 0){
	a = min_cost[chip][now] + e.cost;
      }else{
	a = min(min_cost[chip][now] + e.cost, min_cost[chip-1][now] + e.cost / 2);
	if(min_cost[chip][e.to] > a){
	  min_cost[chip][e.to] = a;
	  que.push(P(min_cost[chip][e.to], e.to));
	}
      }
    }
  }
}

int main(){
  
  while(cin >> c >> V >> m >> s >> d && (c||V||m||s||d)){
    s--;
    d--;
    
    for(int i=0;i<m;i++){
      int a,b,f;
      cin>>a>>b>>f;
      a--;b--;
      Graph[a].push_back(edge(b,f));
      Graph[b].push_back(edge(a,f));
    }
    
    for(int i=0;i<=c;i++){
      Dijkstra(s,i);
    }

    cout<<min_cost[c][d]<<endl;
    
    for(int i=0;i<V;i++) Graph[i].clear();
  }
  return 0;
}
    
    