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]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 <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <typename T>
struct edge {
    int from, to; T cost;
    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template <class K, class V>
class RadixHeap {
    static constexpr int bit_length = sizeof(K)*8;
    K last;
    size_t sz, cnt;

    array<vector<pair<K, V>>, bit_length> v;
    static inline int bsr(int x){
        return x ? bit_length-__builtin_clz(x) : 0;
    }
    static inline int bsr(ll x){
        return x ? bit_length-__builtin_clzll(x) : 0;
    }

    void pull() {
        if(cnt < v[0].size()) return;;
        int i = 1;
        while(v[i].empty()) i++;
        last = min_element(v[i].begin(),v[i].end())->first;
        for (auto &&x : v[i]) v[bsr(x.first ^ last)].push_back(x);
        v[i].clear();
    }
public:
    RadixHeap() : last(0), sz(0), cnt(0) {}
    void emplace(K x, V val){
        sz++;
        v[bsr(x^last)].emplace_back(x, val);
    }

    pair<K, V> top() {
        pull();
        return v[0][cnt];
    }

    void pop() {
        pull();
        sz--;
        cnt++;
    }

    size_t size() const { return sz; }
    bool empty() const { return !sz; }
};
template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

bool solve(){
    int c, n, m, s, g;
    cin >> c >> n >> m >> s >> g;
    if(!c) return 0;
    s--; g--;
    vector<vector<edge<int>>> G(n);
    for (int i = 0; i < m; ++i) {
        int a, b, f;
        cin >> a >> b >> f;
        a--; b--;
        G[a].emplace_back(b, f);
        G[b].emplace_back(a, f);
    }
    auto dp = make_v(c+1, n, INF<int>);
    dp[0][s] = 0;
    RadixHeap<int, pair<int, int>> Q;
    Q.emplace(0, {0, s});
    while(!Q.empty()){
        int a, x; tie(a, x) = Q.top().second; int C = Q.top().first;
        Q.pop();
        if(dp[a][x] < C) continue;
        for (auto &&e : G[x]) {
            if(a != c){
                if(dp[a+1][e.to] > C+e.cost/2) {
                    dp[a+1][e.to] = C+e.cost/2;
                    Q.emplace(C+e.cost/2, {a+1, e.to});
                }
            }
            if(dp[a][e.to] > C+e.cost){
                dp[a][e.to] = C+e.cost;
                Q.emplace(C+e.cost, {a, e.to});
            }
        }
    }
    int ans = INF<int>;
    for (int i = 0; i <= c; ++i) {
        chmin(ans, dp[i][g]);
    }
    cout << ans << "\n";
    return 1;
}

int main() {
    while(solve());
    return 0;
}

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

#define rep(i,n)	for(int i = 0;i < n;i++)
#define rep2(i,n)	for(int i = 1;i <= n;i++)
#define each(i,x)	for(auto & i : x)

struct edge
{
	edge(int _s,int _t,int _cost)
	{
		s = _s;t = _t;cost = _cost;
	}
	int s;
	int t;
	int cost;
};

using namespace std;

int main()
{
	int c,n,m,s,d;
	cin >> c >> n >> m >> s >> d;
	while(c || n || m || s || d)
	{
		s--;d--;
		vector<list<edge>> town(n);
		vector<edge> eary;
		rep(i,m)
		{
			int a,b,f;
			cin >> a >> b >> f;
			a--;b--;
			town[a].push_back(edge(a,b,f));
			town[b].push_back(edge(b,a,f));
			eary.push_back(edge(a,b,f));
		}
		vector<vector<int>> cost(c+1,vector<int>(n,2000000));
		cost[0][s] = 0;
		bool flg;
		do
		{
			flg = false;
			each(e,eary)
			{
				rep(i,c+1)
				{
					if(cost[i][e.s] > cost[i][e.t] + e.cost)
					{
						cost[i][e.s] = cost[i][e.t] + e.cost;
						flg = true;
					}
					else if(cost[i][e.t] > cost[i][e.s] + e.cost)
					{
						cost[i][e.t] = cost[i][e.s] + e.cost;
						flg = true;
					}
				}
				rep(i,c)
				{
					if(cost[i+1][e.s] > cost[i][e.t] + e.cost/2)
					{
						cost[i+1][e.s] = cost[i][e.t] + e.cost/2;
						flg = true;
					}
					if(cost[i+1][e.t] > cost[i][e.s] + e.cost/2)
					{
						cost[i+1][e.t] = cost[i][e.s] + e.cost/2;
						flg = true;
					}
				}
			}
		}while(flg);
		int min = 10000000;
		rep(i,c+1)
		{
			if(cost[i][d] < min)
			{
				min = cost[i][d];
			}
		}
		cout << min << endl;
		cin >> c >> n >> m >> s >> d;
	}
	return 0;
}