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<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<queue>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define INF 1000000007
#define MOD 1000000007
#define ARRAY_MAX 105
#define TICKET 15

int c,n,m,s,d;
vector<P> G[ARRAY_MAX];//to,cost
int cost[TICKET][ARRAY_MAX];//チケットの残り枚数、最短距離
bool used[TICKET][ARRAY_MAX];


void solve(){

    cost[c][s] = 0;//出発点
    priority_queue<pair<int,P>,vector<pair<int,P> >,greater<pair<int,P> > > que;
    que.push(pair<int,P>(0,P(s,c)));//コスト、現在位置、残りのチケット枚数
    while(!que.empty()){

        pair<int,P> tmp = que.top();
        que.pop();
        int now_position = tmp.second.first;//現在位置
        int now_ticket = tmp.second.second;//残りのチケット枚数
        int now_cost = tmp.first;//次の町までのコスト

        if(cost[now_ticket][now_position] < now_cost){
            continue;
        }


        for(int i = 0;i < G[now_position].size();i++){
            //チケットを使わない場合
            if(cost[now_ticket][G[now_position][i].first] > cost[now_ticket][now_position] + G[now_position][i].second){
                cost[now_ticket][G[now_position][i].first] = cost[now_ticket][now_position] + G[now_position][i].second;
                que.push(pair<int,P>(cost[now_ticket][G[now_position][i].first],P(G[now_position][i].first,now_ticket)));
            }
            //チケットをc枚まで使う場合
            if(now_ticket > 0){
                if(cost[now_ticket-1][G[now_position][i].first] > cost[now_ticket][now_position] + G[now_position][i].second/2){
                    cost[now_ticket-1][G[now_position][i].first] = cost[now_ticket][now_position] + G[now_position][i].second/2;
                    que.push(pair<int,P>(cost[now_ticket-1][G[now_position][i].first],P(G[now_position][i].first,now_ticket-1)));
                }
            }
        }
    }
}

int main(){

    while(cin >> c >> n >> m >> s >> d,c|n|m|s|d){

        s--;
        d--;
        //cout << s << " " << d << endl;
        REP(i,ARRAY_MAX){//初期化
            G[i].clear();
        }

        REP(i,TICKET){//最短距離の初期化
            REP(j,ARRAY_MAX){
                cost[i][j] = INF;
                used[i][j] = false;
            }
        }

        REP(i,m){
            int a,b,f;
            cin >> a >> b >> f;
            a--;
            b--;
            G[a].push_back({b,f});
            G[b].push_back({a,f});
            //マップの作成
        }

        solve();

        int mini = INF;
        for(int i = 0;i <= c;i++){
            mini = min(mini,cost[i][d]);
        }
        cout << mini << endl;
    }


    return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)

typedef long long ll;
struct edge {int to, cost;};
typedef pair<int, int> P;
typedef complex<double> C;

const int INF = 99999999;
const int MAX_V = 110;
const int MAX_E = 510;

int cost[MAX_V][MAX_V];
int d[MAX_V], d2[MAX_V];
bool used[MAX_V];
int pre[MAX_V], pre2[MAX_V];
int V, E;
int c, s, g;

void init_cost() {
    REP(i, V) REP(j, V) cost[i][j] = INF;
}

//s: start
void dijkstra(int s, int *d, int *pre) {
    REP(i, V) d[i] = INF;
    REP(i, V) used[i] = false;
    REP(i, V) pre[i] = -1;
    d[s] = 0;

    while (true) {
        int v = -1;
        REP(u, V) if (!used[u] && (v == -1 | d[u] < d[v])) v = u;

        if (v == -1) break;
        used[v] = true;

        REP(u, V) {
            if (d[u] > d[v] + cost[v][u]) {
                d[u] = d[v] + cost[v][u];
                pre[u] = v;
            }
        }
    }
}

//t: terminal
vector<int> get_path(int t, int *pre) {
    vector<int> path;
    for (; t != -1; t = pre[t]) path.pb(t);
    reverse(ALL(path));
    return path;
}

void solve() {
    dijkstra(s, d, pre);
    dijkstra(g, d2, pre2);

    int ans = INF;

    REP(k, V) {
        vector<int> cost_vec;

        vector<int> path = get_path(k, pre);
        REP(i, path.size() - 1) {
            cost_vec.pb(cost[path[i]][path[i+1]]);
        }

        path = get_path(k, pre2);
        REP(i, path.size() - 1) {
             cost_vec.pb(cost[path[i]][path[i+1]]);
        }

        sort(ALL(cost_vec));
        reverse(ALL(cost_vec));

        // REP(i, cost_vec.size()) printf("%d ", cost_vec[i]);
        // printf("\n");

        int sm = 0;
        REP(i, cost_vec.size()) {
            if (i < c)  sm += cost_vec[i] / 2;
            else        sm += cost_vec[i];
        }

        ans = min(ans, sm);
    }

    printf("%d\n", ans);

}

int main() {
    while (true) {
        scanf("%d%d%d%d%d", &c, &V, &E, &s, &g);
        if (!c) return 0;
        s--; g--;
        init_cost();
        REP(i, E) {
            int f, t, c;
            scanf("%d%d%d", &f, &t, &c);
            f--; t--;
            cost[f][t] = c;
            cost[t][f] = c;
        }
        solve();
    }
}