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]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)
					}
				}
			}
		}
		runtime.GC()
	}
}

C++: #include <iostream>
#include <queue>
#include <array>
#include <vector>

using namespace std;
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

struct edge {
    int to,cost;
};
struct state {
    int v,d;
    bool operator<(const state& s) const {
        return d>s.d;
    }
};

vector<vector<edge>> G;
array<array<int,11>,101> dp;
priority_queue<state> q;
int c,n,m,s,d;

int main(){
    while(cin>>c>>n>>m>>s>>d, c||n||m||s||d){
        G=vector<vector<edge>>(n+1);
        rep(i,m){
            int f,t,c; cin>>f>>t>>c;
            G[f].push_back({t,c});
            G[t].push_back({f,c});
        }
        rep(i,c+1){
            dp[i].fill(1<<30);
            dp[i][s]=0;
            priority_queue<state>().swap(q);
            q.push({s,0});
            while(q.size()){
                state sta=q.top(); q.pop();
                if(dp[i][sta.v]<sta.d) continue;
                for(edge& e:G[sta.v]){
                    int t;
                    if(i==0) t=dp[0][sta.v]+e.cost;
                    else t=min(dp[i][sta.v]+e.cost,
                               dp[i-1][sta.v]+e.cost/2);
                    if(dp[i][e.to]>t){
                        dp[i][e.to]=t;
                        q.push({e.to,t});
                    }
                }
            }
        }
        cout<<dp[c][d]<<endl;
    }
}

C++: #include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;

template <typename T>
struct Edge { int src, dst; T cost;
    Edge(int dst, T cost) : src(-1), dst(dst), cost(cost) { }
    Edge(int src, int dst, T cost) : src(src), dst(dst), cost(cost) { }
};
template <typename T> using Edges = vector<Edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
template <typename T> using Matrix = vector<vector<T>>;

template <typename T>
vector<vector<T>> dijkstra(const WeightedGraph<T> &g, int s, int c) {
    const T INF = numeric_limits<T>::max();
    vector<vector<T>> dp(g.size(), vector<T>(c + 1, INF));
    using Pi = tuple<T, int, int>;
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;
    dp[s][c] = 0; que.emplace(dp[s][c], s, c);
    while (!que.empty()) {
        T cost; int v, cc; tie(cost, v, cc) = que.top(); que.pop();
        if (dp[v][cc] < cost) continue;
        for (auto &e: g[v]) {
            int nv = e.dst; T nc = e.cost;
            if (cc) {
                if (dp[nv][cc - 1] > dp[v][cc] + nc / 2) {
                    dp[nv][cc - 1] = dp[v][cc] + nc / 2;
                    que.emplace(dp[nv][cc - 1], nv, cc - 1);
                }
            }
            if (dp[nv][cc] <= dp[v][cc] + nc) continue;
            dp[nv][cc] = dp[v][cc] + nc;
            que.emplace(dp[nv][cc], nv, cc);
        }
    }
    return dp;
}

int main() {
    int c, n, m, s, d;
    while (cin >> c >> n >> m >> s >> d, s--, d--, n) {
        WeightedGraph<int> g(n);
        while (m--) {
            int a, b, f; cin >> a >> b >> f; a--, b--;
            /*if (a != d) */g[a].emplace_back(b, f);
            /*if (b != d) */g[b].emplace_back(a, f);
        }
        auto res = dijkstra(g, s, c)[d];
        cout << *min_element(res.begin(), res.end()) << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <list>
#include <queue>
#include <map>

static const int INF = 1 << 20;

using namespace std;

struct state
{
	int ticket, id, cost;
};

struct comparator : public binary_function<state, state, bool>
{
	bool operator() (const state &x, const state &y) const { return x.cost > y.cost; }
};

static bool det[11][101];
static int edges[101][101];

int main()
{
	int C,N,M,S,D;
	while(cin>>C>>N>>M>>S>>D,C|N|S|M|D)
	{
		for (int c = 0; c <= C; c++)
			for (int i = 1; i <= N; i++)
				det[c][i] = false;

		for (int i = 1; i <= N; i++)
			for (int j = 1; j <= N; j++)
				edges[i][j] = INF;

		for (int i = 0; i < M; i++)
		{
			int a,b,f;
			cin>>a>>b>>f;
			edges[a][b] = edges[b][a] = f;
		}

		state init = { C, S, 0 };

		// Dijkstra
		priority_queue<state, vector<state>, comparator> Q;
		Q.push(init);

		int min_cost = INF;
		while (!Q.empty())
		{
			state s = Q.top();
			Q.pop();
			if (det[s.ticket][s.id]) continue;
			det[s.ticket][s.id] = true;

			if (s.id == D) min_cost = min(min_cost, s.cost);

			for (int i = 1; i <= N; i++)
			{
				if (edges[s.id][i] == INF) continue;

				int cost = s.cost + edges[s.id][i];
				state s2 = { s.ticket, i, cost };

				if (!det[s2.ticket][s2.id]) Q.push(s2);

				if (s.ticket > 0)
				{
					cost = s.cost + edges[s.id][i] / 2;
					state s3 = { s.ticket - 1, i, cost };
					if (!det[s3.ticket][s3.id]) Q.push(s3);
				}
			}
		}
		cout << min_cost << endl;
	}
	return 0;
}