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]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 <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;
const int INF = 1<<29;
const double EPS = 1e-8;

typedef vector<int> vec;
typedef pair<int,int> P;
struct edge{int to,cost;};

struct node{
    int d,c,n;
    bool operator<( const node& right ) const {
        return d == right.d ? c < right.c : d > right.d;
    }
};

int main(){
    while(1){
        int c, n, m, s, goal;
        scanf("%d%d%d%d%d",&c,&n,&m,&s,&goal);
        if(!c)break;
        s--;goal--;

        vector<vector<edge> > g(n);
        for(int i=0;i<m;i++){
            int a, b, f;
            scanf("%d%d%d",&a,&b,&f);
            a--;b--;
            g[a].push_back((edge){b,f});
            g[b].push_back((edge){a,f});
        }

        vector<vec> d(c+1,vec(n,INF));
        d[c][s] = 0;
        priority_queue<node> que;
        que.push((node){0,c,s});

        int ans = INF;
        while(que.size()){
            node p = que.top(); que.pop();
            //printf("n=%d d=%d c=%d\n",p.n,p.d,p.c);
            if(d[p.c][p.n] < p.d) continue;
            if(p.n == goal){
                ans = p.d;
                break;
            }
            for(int i=0;i<g[p.n].size();i++){
                int to = g[p.n][i].to;
                if(p.c > 0){
                    int dist_to_use_c = p.d + g[p.n][i].cost/2;
                    if(d[p.c-1][to] > dist_to_use_c){
                        d[p.c-1][to] = dist_to_use_c;
                        //printf("pushed d=%d c=%d n=%d\n",dist_to_use_c,p.c-1,to);
                        que.push((node){dist_to_use_c,p.c-1,to});
                    }
                }
                int dist_to = p.d + g[p.n][i].cost;
                if(d[p.c][to] > dist_to){
                    d[p.c][to] = dist_to;
                    //printf("pushed d=%d c=%d n=%d\n",dist_to,p.c,to);
                    que.push((node){dist_to,p.c,to});
                }
            }
        }
        cout << ans << endl;
    }

    return 0;
}

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

struct Edge{
	int to, cost;
};

typedef pair<int, int> P;

const int MAX_V = 3010;
const int INF = 1 << 30;

vector<Edge> vec[MAX_V];
int d[MAX_V][11];	// d[i][j] = ??????????????????j????????¨??????i?????§????????¢
priority_queue<P, vector<P>, greater<P> > que;

int c, n, m, s, d0;

void dijkstra(int s, int a){
	for(int i = 0; i < n; ++i){
		d[i][a] = INF;
	}

	d[s][a] = 0;

	que.push(P(0, s));

	while(!que.empty()){
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v][a] < p.first) continue;
		for(size_t i = 0; i < vec[v].size(); ++i){
			Edge e = vec[v][i];
			int m0 = (a == 0 ? d[v][a] + e.cost : min(d[v][a] + e.cost, d[v][a - 1] + e.cost / 2));
			if(d[e.to][a] > m0){
				d[e.to][a] = m0;
				que.push(P(d[e.to][a], e.to));
			}
		}
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	while(cin >> c >> n >> m >> s >> d0 && !(c == 0 && n == 0 && m == 0 && s == 0 && d0 == 0)){
		--s, --d0;

		for(int i = 0; i < m; ++i){
			int a, b, f;
			cin >> a >> b >> f;
			--a, --b;
			vec[a].push_back(Edge{b, f});
			vec[b].push_back(Edge{a, f});
		}

		for(int i = 0; i <= c; ++i){
			dijkstra(s, i);
			//cout << d[d0][i] << endl;
		}

		cout << d[d0][c] << endl;

		for(int i = 0; i < n; ++i){
			vec[i].clear();
		}
	}

	return 0;
}

/*
?????????????????°
??????????????????????????°
?????????????????°
???????????????????????±
?????\?????¨??????????????°????????? ?????°?????§???????????????????????????????????????????????°???????????????????????????????????? 
?????????????????° c ??? 1 ??\??? 10 ??\???
??????????????????????????° n ??? 2 ??\??? 100 ??\???
?????????????????° m ??? 1 ??\??? 500 ??\?????? ??´??°??¨????????????
??????????????????????????????????????§??????????????????
?????? f ??? 1000 ??\??? 10000 ??\?????? 100 ???????????´??°??§??????
????????????????????????????????°?????? 1 ?????? n ?????§????????????????????????????????????
????????° s ??¨ ????????° d ?????\????????§??????????????????????????????????????¨????????????
*/