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
}

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)
		for len(pq) != 0 {
			now := heap.Pop(&pq).(*Node)
			if now.NowPosition == d {
				fmt.Println(now.Amount)
				break
			}
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				heap.Push(&pq, next)
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					heap.Push(&pq, next)
				}
			}
		}
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <numeric>

using namespace std;

struct edge{ int to, cost; };
typedef pair<int, int> P;
const int INF = 1 << 29;

int V;
vector<edge> G[100];
int D[100];
int pre[100];

int c, n, m, s, d;

void dijkstra(int s)
{
	priority_queue<P, vector<P>, greater<P> > que;
	fill(D, D + 100, INF);
	fill(pre, pre + 100, -1);
	D[s] = 0;
	que.push(P(0, s));

	while (!que.empty())
	{
		P p = que.top(); que.pop();
		int v = p.second;
		if (D[v] < p.first) continue;
		for (int i = 0; i < G[v].size(); i++)
		{
			edge e = G[v][i];
			if(D[e.to] > D[v] + e.cost)
			{
				D[e.to] = D[v] + e.cost;
				pre[e.to] = v;
				que.push(P(D[e.to], e.to));
			}
		}
	}
}

int solve()
{
	dijkstra(s - 1);
	vector<int> vec;
	for (int t = d - 1; pre[t] != -1 ; t = pre[t])
	{
		for (int i = 0; i < G[t].size(); i++)
		{
			if(pre[t] == G[t][i].to)
			{
				vec.push_back(G[t][i].cost);
				break;
			}
		}
	}
	sort(vec.begin(), vec.end(), greater<int>());
	for (int i = 0; i < c && i < vec.size(); i++)
	{
		vec[i] = vec[i] / 2;
	}
	return accumulate(vec.begin(), vec.end(), 0);
}

int main()
{
	while (cin >> c >> n >> m >> s >> d && c && n && m && s && d)
	{
		for (int i = 0; i < 100; i++)
		{
			G[i] = vector<edge>();
		}
		for (int i = 0; i < m; i++)
		{
			int a, b, f;
			cin >> a >> b >> f;
			edge e;
			e.to = b - 1;
			e.cost = f;
			G[a - 1].push_back(e);
			e.to = a - 1;
			e.cost = f;
			G[b - 1].push_back(e);
		}
		cout << solve() << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <tuple>
#include <queue>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;
typedef tuple<int, int> P;
typedef tuple<ll, int, int> T;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

template<typename T>
void chmin(T &a, T b) {
    a = min(a, b);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int c, n, m, s, t;
    while (cin >> c >> n >> m >> s >> t, c + n + m + s + t) {
        s--;
        t--;
        vector<vector<P>> G(n);
        REP(i, 0, m) {
            int a, b, f;
            cin >> a >> b >> f;
            a--;
            b--;
            G[a].push_back({b, f});
            G[b].push_back({a, f});
        }
        const ll inf = 1LL << 60;
        auto dist = make_v(n, c + 1, inf);
        priority_queue<T, vector<T>, greater<T>> pq;
        // cost, ticket, vertex
        pq.emplace(0LL, c, s);
        REP(i, 0, c + 1) {
            dist[s][i] = 0;
        }
        while (pq.size()) {
            ll cost;
            int ticket, vertex;
            tie(cost, ticket, vertex) = pq.top();
            pq.pop();
            if (dist[vertex][ticket] < cost) continue;
            dist[vertex][ticket] = cost;
            for (auto p : G[vertex]) {
                int to, f;
                tie(to, f) = p;
                // use ticket
                if (ticket > 0 && dist[to][ticket - 1] > cost + f / 2) {
                    dist[to][ticket - 1] = cost + f / 2;
                    pq.emplace(dist[to][ticket - 1], ticket - 1, to);
                }
                // do not use ticket
                if (dist[to][ticket] > cost + f) {
                    dist[to][ticket] = cost + f;
                    pq.emplace(dist[to][ticket], ticket, to);
                }
            }
        }
        ll ans = inf;
        REP (i, 0, c + 1) {
            chmin(ans, dist[t][i]);
        }
        cout << ans << endl;
    }

    return 0;
}

C++: //Solution for aoj:0212 Highway Express Bus
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int, int>P;


struct S {
	int cost, to, num, jud;
	S(int c, int t, int n, int j) : cost(c), to(t), num(n), jud(j) {}
	bool operator<(const S &s) const {
		return cost < s.cost;
	}
};

const int INF = 1 << 31;
int c, n, m, s, d, w;
int tocost[101][11];
vector<P> town[101];
priority_queue<S> pq;

void pq_set(int p, int sum, int j){
	for (int i = 0; i < town[p].size(); i++){
			pq.push(S(town[p][i].second + sum, town[p][i].first, j, 0));
			if (j)
				pq.push(S(town[p][i].second / 2 + sum, town[p][i].first, j - 1, 1));
	}
}

void dijkstra(){
	while (!pq.empty()){
		S a = pq.top();
		pq.pop();
		if (a.jud){
			if (tocost[a.to][a.num] < a.cost&&a.to!=s){
				tocost[a.to][a.num] = a.cost;
					pq_set(a.to, tocost[a.to][a.num], a.num);

			}
		}
			else{
				if (tocost[a.to][a.num] < a.cost&&a.to!=s){
					tocost[a.to][a.num] = a.cost;
					pq_set(a.to, tocost[a.to][a.num], a.num);
					
				}
			}
	}
}
	int main(){
		while (cin >> c >> n >> m >> s >> d&&c){
			for (int i = 0; i < 101; i++)
				fill(tocost[i], tocost[i] + 11, INF);
			fill(tocost[s], tocost[s] + 11, 0);
			while (pq.size())
				pq.pop();
			for (int i = 0; i < n; i++)
					town[i].erase(town[i].begin(),town[i].end());
			for (int i = 0; i < m; i++){
				int a, b, c;
				cin >> a >> b >> c;
				town[a].push_back({ b, c*-1 });
				town[b].push_back({ a, c*-1 });
			}
			pq_set(s, 0, c);
			dijkstra();
			cout << -tocost[d][0] << endl;
		}
	}