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)
		}
		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)
		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++: #include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

int calcCost(int c, int n, vector<int> path, vector<int> rt){
	priority_queue<int> costs;
	for(int i=1; i<rt.size(); i++){
		costs.push(path[rt[i]+n*rt[i-1]]);
	}
	int total = 0;
	while(costs.size() && c--){
		total += costs.top() / 2;
		costs.pop();
	}
	while(costs.size()){
		total += costs.top();
		costs.pop();
	}
	return total;
}
int main(){
	for(;;){
		int c,n,m,s,d;
		cin>>c>>n>>m>>s>>d;
		if(c+n+m+s+d==0) break;
		vector<pair<int, vector<int>>> route(n,make_pair(-1,vector<int>()));
		vector<int> path(n*n,-1);
		for(int i=0; i<m; i++){
			int a,b,f;
			cin>>a>>b>>f;
			path[--a+n*--b] = path[b+n*a] = f;
		}
		priority_queue<pair<int, vector<int>>, vector<pair<int, vector<int>>>, greater<pair<int, vector<int>>>> pq;
		pq.push(make_pair(0,vector<int>(1,s-1)));
		while(pq.size()){
			int cur = *(pq.top().second.rbegin());
			if(route[cur].first == -1){
				route[cur] = pq.top();
				for(int i=0; i<n; i++){
					if(route[i].first == -1 && path[i+n*cur] != -1){
						auto copy = pq.top();
						copy.second.push_back(i);
						copy.first = calcCost(c,n,path,copy.second);
						pq.push(copy);
					}
				}
			}
			pq.pop();
		}
		cout<<route[d-1].first<<endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <stack>
#include <list>

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,b,n) for(int i=b;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

const float PI = 3.1415926;
static const int INFTY = (1<<30);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int MAX = 100;

using namespace std;

typedef long long ll;
typedef long double ld;

int c, n, m, s, d;
int C[101][101], D[101][101];
int DP[101][16];

// co=割引券, cost=現在の値段
void solve(int st, int co, int cost) {
  if (st == d-1) {
    return;
  }
  // 次の町探し
  rep(i, n) {
    if (i == st || C[st][i] == INFTY) {
      continue;
    }
    int tmp = cost + C[st][i];
    int tmp2 = cost + C[st][i]/2;
    if (DP[i][co] > tmp) {
      DP[i][co] = tmp;
      solve(i, co, tmp);
    }
    if (co < c && DP[i][co+1] > tmp2) {
      DP[i][co+1] = tmp2;
      solve(i, co+1, tmp2);
    }
  }
}


int main() {
  while (cin >> c >> n >> m >> s >> d, c) {
    rep(i, n) {
      rep(j, n) {
        C[i][j] = INFTY;
        D[i][j] = INFTY;
      }
      rep (q, c+1) {
        DP[i][q] = INFTY;
      }
    }
    rep(i, m) {
      int a,b,f;
      cin >> a >> b  >> f;
      C[a-1][b-1] = f;
      C[b-1][a-1] = f;
    }
    solve(s-1, 0, 0);
    int res = INFTY;
    rep(i, c+1) {
      res = min(res, DP[d-1][i]);
    }
    cout << res << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P ,P>;
constexpr ll MOD = ll(1e9+7);
constexpr int IINF = INT_MAX;

vector<vector<P> > g;
int dist[105][15];

int main(){
    int c, n, m, s, d;
    while(cin >> c >> n >> m >> s >> d, n){
        s--; d--;
        g.clear();
        g.resize(n);
        for(int i=0;i<m;i++){
            int a, b, f;
            cin >> a >> b >> f;
            a--; b--;
            g[a].push_back(P(b,f));
            g[b].push_back(P(a,f));
        }
        for(int i=0;i<n;i++){
            fill(dist[i], dist[i]+c+1, IINF/2);
        }
        dist[s][c] = 0;
        priority_queue<P3, vector<P3>, greater<P3> > que;
        que.push(P3(0, P(s, c)));
        while(!que.empty()){
            auto p = que.top();
            que.pop();
            int now = p.second.first, r = p.second.second;
            if(dist[now][r] < p.first) continue;
            for(auto e : g[now]){
                int nxt = e.first, f = e.second;
                if(dist[nxt][r] > dist[now][r] + f){
                    dist[nxt][r] = dist[now][r] + f;
                    que.push(P3(dist[nxt][r], P(nxt,r)));
                }
                if(r>0 && dist[nxt][r-1] > dist[now][r] + f/2){
                    dist[nxt][r-1] = dist[now][r] + f/2;
                    que.push(P3(dist[nxt][r-1], P(nxt,r-1)));
                }
            }
        }
        int ans = IINF;
        for(int i=0;i<=c;i++){
            ans = min(ans, dist[d][i]);
        }
        cout << ans << endl;
    }

    return 0;
}