Go: package main

import (
	"container/heap"
	"fmt"
)

type Node struct {
	NowPosition          int
	DiscountTicketTCount int
	Amount               int
}

type PriorityQueueNode []*Node

func (pq PriorityQueueNode) Len() int {
	return len(pq)
}

func (pq PriorityQueueNode) Less(i, j int) bool {
	return pq[i].Amount < pq[j].Amount
}

func (pq PriorityQueueNode) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueueNode) Push(node interface{}) {
	*pq = append(*pq, node.(*Node))
}

func (pq *PriorityQueueNode) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	*pq = old[0 : n-1]
	return item
}

type Point struct {
	NextPoint int
	Fee       int
}

type Memo struct {
	NowPoint             int
	DiscountTicketTCount int
}

func main() {
	var c, n, m, s, d int
	var a, b, f int

	for {
		fmt.Scan(&c, &n, &m, &s, &d)
		if c == 0 && n == 0 && m == 0 && s == 0 && d == 0 {
			break
		}
		s--
		d--
		pointMap := make([][]Point, n)
		for i := 0; i < n; i++ {
			pointMap[i] = make([]Point, 0, n)
		}
		for i := 0; i < m; i++ {
			fmt.Scan(&a, &b, &f)
			a--
			b--
			pointMap[a] = append(pointMap[a], Point{NextPoint: b, Fee: f})
			pointMap[b] = append(pointMap[b], Point{NextPoint: a, Fee: f})
		}
		pq := make(PriorityQueueNode, 0, m)
		start := Node{NowPosition: s, DiscountTicketTCount: c, Amount: 0}
		heap.Push(&pq, &start)
		memo := make(map[Memo]struct{})
		for len(pq) != 0 {
			now := heap.Pop(&pq).(*Node)
			if now.NowPosition == d {
				fmt.Println(now.Amount)
				break
			}
			memo[Memo{NowPoint: now.NowPosition, DiscountTicketTCount: now.DiscountTicketTCount}] = struct{}{}
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				if _, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok {
					heap.Push(&pq, next)
				}
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					if _, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok {
						heap.Push(&pq, next)
					}
				}
			}
		}
	}
}

C++: /* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
/* }}} */

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

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T> void print(T x) {std::cout << x << '\n';}
template <typename T>
void print(std::vector<T>& v, std::string s = " ") {
  REP(i, v.size()) {
    if (i != 0) std::cout << s;
    std::cout << v[i];
  }
  std::cout << '\n';
}

/* }}} */

struct Edge {
  int to, cost;
};

vector<vector<Edge>> edge;

void dijkstra(int s, int c, vvi& dp)
{
  priority_queue<pii, vector<pii>, greater<pii>> pq;
  dp[s][c] = 0;
  pq.push(mp(0, s));

  while (!pq.empty()) {
    pii p = pq.top(); pq.pop();
    int cur = p.Se;
    if (dp[cur][c] < p.Fi) continue;
    for (auto e : edge[cur]) {
      int t = c == 0 ? dp[cur][c] + e.cost : min(dp[cur][c] + e.cost, dp[cur][c - 1] + e.cost / 2);
      if (dp[e.to][c] > t) {
        dp[e.to][c] = t;
        pq.push(mp(dp[e.to][c], e.to));
      }
    }
  }
}

signed main()
{
  int c, n, m, s, d;

  while (cin>>c>>n>>m>>s>>d, c||n||m||s||d) {
    s--; d--;
    edge = vector<vector<Edge>>(n);
    vvi dp(n, vi(c + 1, INF));
    REP(i, m) {
      int a = in() - 1, b = in() - 1, f = in();
      edge[a].pb(Edge{b, f});
      edge[b].pb(Edge{a, f});
    }
    REP(i, c + 1) {
      dijkstra(s, i, dp);
    }
    print(dp[d][c]);
  }

  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

/* 現在地 コスト 使った枚数 */
typedef tuple<int,int,int> tp;
typedef pair<ll,ll> P;

/* 町 使った割引券の数 */
ll dist[105][15];
vector<P> G[105];
const ll MAX=LLONG_MAX/10;

void init(){
  for(int i=0;i<105;i++){
    G[i].clear();
    for(int j=0;j<15;j++){
      dist[i][j]=MAX;
    }
  }
}

void solve(int c,int n,int m,int s,int d){
  init();
  int a,b,f;
  for(int i=0;i<m;i++){
    cin>>a>>b>>f;
    G[a].push_back(mp(b,f));
    G[b].push_back(mp(a,f));
  }

  /* 現在地 使った枚数 */
  priority_queue<tp,vector<tp>,greater<tp> > que;
  que.push(make_tuple(s,0,0));
  dist[s][0] = 0;
  while(que.size()){
    ll now,cost,num;
    tie(now,cost,num)=que.top();que.pop();
    if(dist[now][num]<cost)continue;
    for(auto x : G[now]){      
      /* 割引券を使わない */
      if(cost+x.second<dist[x.first][num]){
        dist[x.first][num] = cost+x.second;
        que.push(make_tuple(x.first,dist[x.first][num],num));
      }
      /* 割引券が残っていたら使う */
      if(num<c&&cost+x.second/2<dist[x.first][num+1]){
          dist[x.first][num+1] = cost+x.second/2;
          // cout<<now<<" "<<x.first<<" = "<< dist[x.first][num+1] << endl;
          que.push(make_tuple(x.first,dist[x.first][num+1],num+1));
        }
    }
  }

  ll ans=LLONG_MAX;
  for(int i=0;i<15;i++)
      ans=min(ans,dist[d][i]);
  ans=min(ans,dist[d][c]);
  
  cout<<ans<<endl;
}


int main(){
  int c,n,m,s,d;
  while(cin>>c>>n>>m>>s>>d,c|n|m|s|d){
    solve(c,n,m,s,d);
  }
}