Go: package main

import (
	"container/heap"
	"fmt"
	"runtime"
)

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]int)
		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}] = now.Amount
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				if memoAmount, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok || (ok && memoAmount > next.Amount) {
					memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}] = next.Amount
					heap.Push(&pq, next)
				}
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					if memoAmount, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok || (ok && memoAmount > next.Amount) {
						memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}] = next.Amount
						heap.Push(&pq, next)
					}
				}
			}
		}
		runtime.GC()
	}
}

C++: #include "bits/stdc++.h"
using namespace std;
const int MOD = (int)1e9 + 7, INF = (1 << 27); const ll INFLL = (1LL << 55);
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
template<typename T> void dbg(T x) { cout << x << "\n"; }
template<typename T, typename U> static void chmin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void chmax(T &x, U y) { if (x < y) x = y; }


int n, m;

// O(n^2)
using Dist = int;
const int VMAX = 110;
Dist cost[VMAX][VMAX];
Dist d[12][VMAX];
void dijkstra(int s, int a) {
    d[a][s] = 0;
    vector<int> used(n, 0);
    while (1) {
        int v = -1;
        for (int to = 0; to < n; to++) {
            if (used[to]) continue;
            if (v == -1 || d[a][to] < d[a][v]) v = to;
        }
        if (v == -1) break;
        used[v] = 1;
        for (int to = 0; to < n; to++) {
            Dist nd = d[a][v] + cost[v][to];
            if (a > 0) chmin(nd, d[a - 1][v] + cost[v][to] / 2);
            if (nd < d[a][to]) d[a][to] = nd;
        }
    }
}

void init() {
    fill_n(*d, 12 * VMAX, INF);
    fill_n(*cost, VMAX * VMAX, INF);
}

int main() {
    int c, s, t;
    while (cin >> c >> n >> m >> s >> t, c) {
        init();
        s--; t--;
        rep(i, m) {
            int a, b, f; cin >> a >> b >> f;
            a--; b--;
            cost[a][b] = cost[b][a] = f;
        }
        rep(a, c + 1) dijkstra(s, a);
        cout << d[c][t] << "\n";
    }

    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;// F -> to, S -> cost
typedef pair<P,int> PP;// F->P(to,cost), S->discount
int c,n,m,s,d;
vector<P> vec[1000]; // F -> pos , S -> cost
int MD[1000][13];
const int INF = 1<<27;

//C++だとなぜかRuntimeErrorになったので仕様変更
//vecにはコストいらないからvector<PP> vec -> vector<P> vec へ


void dijkstra(){
  priority_queue<PP,vector<PP>,greater<PP> > que;
  rep(i,n+1)rep(j,13)MD[i][j] = INF;
  //syokika
  MD[s][c] = 0;
  que.push(PP(P(0,s),c));//dis,start,discount

  while(!que.empty() ){
    PP p = que.top();que.pop(); //priority_queのPPと
    int v = p.F.S;
    
    for(int i=0;i<vec[v].size();i++){
      P po = vec[v][i]; //vectorのPPは意味が違うので注意！！！
      //if(MD[v][po.S] < po.F.S)continue;
      if(MD[po.F][p.S] > p.F.F + po.S){
	MD[po.F][p.S] = p.F.F+po.S;
	que.push(PP(P(MD[po.F][p.S],po.F),p.S));
      }
      if(p.S > 0 && MD[po.F][p.S-1] > p.F.F + po.S/2 ){
	MD[po.F][p.S-1] = p.F.F+po.S/2;
	que.push(PP(P(MD[po.F][p.S-1],po.F),p.S-1));
   
      }
    }
  }
}


int main(){
  int x,y,co;
  while(true){
    cin >> c >> n >> m >> s >> d;
    if(c+n+m+s+d == 0)break;
    rep(i,1000)vec[i].clear();
    rep(i,m){
      cin >> x >> y >> co;
      vec[x].push_back(P(y,co));
      vec[y].push_back(P(x,co));
    }
    dijkstra();
    int ans = INF;
    for(int i=0;i<=c;i++){
      ans = min(ans,MD[d][i]);
    }
    cout << ans << endl;
  }
  return 0;
}

//Version.1

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }


struct edge
{
  int to, cost;
  edge(int to, int cost) : to(to), cost(cost) {}
};

struct P
{
  int pnt, ticket, cost;
  P(int pnt = 0, int ticket = 0, int cost = 0) : pnt(pnt), ticket(ticket), cost(cost) {}
};

bool operator>(const P& left, const P& right)
{
  return left.cost > right.cost;
}

int D[16][128];

int main()
{
  int c, n, m, s, d;
  while(cin >> c >> n >> m >> s >> d && c){
    memset(D, -1, sizeof D);
    vector<vector<edge> > edges(n);

    rep(i, m){
      int a, b, f;
      cin >> a >> b >> f;

      edges[a - 1].push_back(edge(b - 1, f));
      edges[b - 1].push_back(edge(a - 1, f));
    }

    priority_queue<P, vector<P>, greater<P> > que;
    for(que.push(P(s - 1, c, 0)); !que.empty(); que.pop()){
      P v = que.top();

      if(D[v.ticket][v.pnt] != -1 && D[v.ticket][v.pnt] <= v.cost) continue;
      D[v.ticket][v.pnt] = v.cost;
      
      rep(i, edges[v.pnt].size()){
	int to = edges[v.pnt][i].to, cost = edges[v.pnt][i].cost;

	que.push(P(to, v.ticket, v.cost + cost));
	if(0 < v.ticket) que.push(P(to, v.ticket - 1, v.cost + cost / 2));
      }
    }

    int ans = 1 << 30;
    rep(i, c+1) if(D[i][d - 1] != -1) chmin(ans, D[i][d - 1]);

    cout << ans << endl;
  }
}