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 <algorithm>
#include <vector>
using namespace std;

class edge{
	public:
		int to,cost;
		edge();
		edge(int _to,int _cost){
			to = _to;
			cost = _cost;
		}
};
class state{
	public:
		int id,cost,ticket;
		state();
		state(int _id,int _cost,int _ticket){
			id = _id;
			cost = _cost;
			ticket = _ticket;
		}
		bool operator<(const state st)const{
			return cost > st.cost;
		}
};
const int INF = 1000000000;

int main()
{
	int c,n,m,s,g;
	while(cin >> c >> n >> m >> s >> g){
		if(!c&&!n&&!m&&!s&&!g)
			break;
		vector<edge> t[101];
		int d[101][11];
		for(int i=0;i<m;i++){
			int a,b,cost;
			cin >> a >> b >> cost;
			a--;b--;
			t[a].push_back(edge(b,cost));
			t[b].push_back(edge(a,cost));
		}
		s--;g--;

		int ans = INF;
		for(int j=0;j<101;j++){
			for(int i=0;i<11;i++){
				d[j][i] = INF;
			}
		}
		d[s][c] = 0;
		priority_queue<state> que;
		que.push(state(s,0,c));
		while(!que.empty()){
			state st = que.top();
			que.pop();
			int v = st.id;
			if(st.id == g)
				ans = min(ans,st.cost);
			for(unsigned i=0;i<t[v].size();i++){
				edge e = t[v][i];	
				if( d[e.to][st.ticket] > d[v][st.ticket] + e.cost){
					d[e.to][st.ticket] = d[v][st.ticket] + e.cost;
					que.push(state(e.to,d[e.to][st.ticket],st.ticket));
				}
				if(st.ticket>0){
					if( d[e.to][st.ticket-1] > d[v][st.ticket] + (e.cost)/2){
						d[e.to][st.ticket-1] = d[v][st.ticket] + (e.cost)/2;
						que.push(state(e.to,d[e.to][st.ticket-1],st.ticket-1));
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define Rrep(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int c, n, m, s, d;
int a, b, f;
struct edge {int to, cost;};
vector<edge> G[105];
vector<vector<int> > dp(11, vector<int>(105, 0));

void dijkstra(int s, int a) {
	priority_queue<P, vector<P>, greater<P> > que;
	rep(i, 105) dp[a][i] = INF;
	dp[a][s] = 0;
	que.push(P(0, s));

	while(!que.empty()) {
		P p = que.top(); que.pop();
		int tmp = p.second;
		if(dp[a][tmp] < p.first) continue;
		rep(i, G[tmp].size()) {
			int to = G[tmp][i].to;
			int cost = (a == 0) ? G[tmp][i].cost + dp[a][tmp] : min(G[tmp][i].cost + dp[a][tmp], G[tmp][i].cost / 2 + dp[a - 1][tmp]);
			if(dp[a][to] > cost) {
				dp[a][to] = cost;
				que.push(P(-cost, to));
			}
		}
	}

}

int main() {
	while(scanf("%d %d %d %d %d", &c, &n, &m, &s, &d)) {
		s--; d--;
		if(c == 0) return 0;
		rep(i, m) {
			scanf("%d %d %d", &a, &b, &f); 
			a--; b--;
			G[a].push_back((edge){b, f});
			G[b].push_back((edge){a, f});
		}
		int ans = INF;
		rep(i, c + 1) dijkstra(s, i);
		printf("%d\n", dp[c][d]);

		rep(i, 105){
      		G[i].erase(G[i].begin(), G[i].end());
    	}
    	rep(i, 11){
      		dp[i].erase(dp[i].begin(), dp[i].end());
    	}
	}
	return 0;
}

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

#define reep(i,n,m) for(int i=(n);i<(m);i++)
#define rep(i,n) reep(i,0,n)

using namespace std;

class Edge{
public:
    int to;
    int cost;
    Edge(int to,int cost):to(to),cost(cost){}
};

class Node{
public:
    int distance;
    int num;
    int ticket;
    Node(){}
    Node(int distance, int num,int ticket):distance(distance),num(num),ticket(ticket){}
    bool operator<(const Node &b)const{
        return distance > b.distance;
    }
};

vector<Edge> edge[101];
bool flg[101][11];

void init(){
    rep(i,101){
        edge[i].clear();
        rep(k,11){
            flg[i][k] = 0;
        }
    }
}

int main(){
    int c,n,m,s,d;
    while(cin >> c >> n >> m >> s >> d,!m==0){
        init();
        rep(i,m){
            int a,b,c;
            cin >> a >> b >> c;
            edge[a].push_back(Edge(b,c));
            edge[b].push_back(Edge(a,c));
        }
        priority_queue<Node> Q;
        Q.push(Node(0,s,0));
        int ans = 1000000;
        while(!Q.empty()){
            Node node = Q.top();Q.pop();
            if(flg[node.num][node.ticket]){
                continue;
            }
            flg[node.num][node.ticket] = true;
            //printf("num->%d cost->%d ticket->%d\n",node.num,node.distance,node.ticket);
            if(node.num == d){
                ans = min(ans,node.distance);
            }

            rep(i,edge[node.num].size()){
                Edge e = edge[node.num][i];
                int cost = node.distance + e.cost;
                Q.push(Node(cost,e.to,node.ticket));
                if(node.ticket < c){
                    int cost = node.distance + e.cost/2;
                    Q.push(Node(cost,e.to,node.ticket+1));
                }
            }
        }
        cout << ans << endl;
    }
}