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 <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

struct state {
	int p, t, c;
	state(int p, int t, int c) : p(p), t(t), c(c) {};
	bool operator<(const state &o)const {
		return o.c<c;
	}
};

int main() {
	int c, n, m, s, d;
	while(cin >> c >> n >> m >> s >> d, c) {
		vvi dist(n, vi(n, INF));
		int a, b, f;
		REP(i, m) {
			cin >> a >> b >> f;
			dist[a-1][b-1] = dist[b-1][a-1] = f;
		}
	

		priority_queue<state> Q;
		vvi cost(n, vi(c+1, INF));
		Q.push(state(s-1, 0, 0));
		cost[s-1][0] = 0;
		while(!Q.empty()) {
			state st = Q.top();
			Q.pop();

			if(st.p == d-1) {
				continue;
			}

			REP(i, n) {
				if(st.p != i) {
					if(st.t < c) {
						int nc = st.c + dist[st.p][i]/2;
						if(nc < cost[i][st.t+1]) {
							cost[i][st.t+1] = nc;
							Q.push(state(i, st.t+1, nc));
						}
					}
					int nc = st.c + dist[st.p][i];
					if(nc < cost[i][st.t]) {
						cost[i][st.t] = nc;
						Q.push(state(i, st.t, nc));
					}
				}
			}
		}

		int ans = INF;
		REP(i, c+1) {
			ans = min(ans, cost[d-1][i]);
		}

		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

class Edge{
public:
	int from,to,cost;
	void Swap(){
		int a = from;
		from = to;
		to = a;
	}
};

vector<Edge> edges;

const int INF = 999999999;

int solve(int s,int g,int c){
	int d[101][11];
	bool flag[101][11];
	for(int i=0;i<101;i++){
		for(int j=0;j<11;j++){
			d[i][j] = INF;
			flag[i][j] = false;
		}
	}
	d[s][c] = 0;
	
	vector<Edge>::iterator eit;
	
	while(1){
		int no,nc;
		bool f = true;
		for(int i=0;i<101;i++){
			for(int j=c;j>=0;j--){
				if(d[i][j] != INF && flag[i][j] == false){
					if(f){
						no = i;
						nc = j;
					}else if(d[no][nc] > d[i][j]){
						no = i;
						nc = j;
					}
					f = false;
				}
			}
		}
		if(f){break;}
		flag[no][nc] = true;
		for(eit = edges.begin();eit != edges.end(); eit++){
			if(eit->from == no){
				if(d[eit->to][nc] > d[eit->from][nc] + eit->cost){
					d[eit->to][nc] = d[eit->from][nc] + eit->cost;
				}
				if(nc > 0){
					if(d[eit->to][nc - 1] > d[eit->from][nc] + eit->cost / 2){
						d[eit->to][nc - 1] = d[eit->from][nc] + eit->cost / 2;
					}
				}
			}
		}
	}
	int ans = INF;
	for(int i=0;i<c;i++){
		if(d[g][i] < ans){
			ans = d[g][i];
		}
	}
	return ans;
}

int main(){
	int c,n,m,s,d;
	int a,b,f;
	while(1){
		scanf("%d %d %d %d %d",&c,&n,&m,&s,&d);
		if(c == 0 && n == 0 && m == 0 && s == 0 && d == 0){
			break;
		}
		edges.clear();
		for(int i=0;i<m;i++){
			scanf("%d %d %d",&a,&b,&f);
			Edge e;
			e.from = a;
			e.to = b;
			e.cost = f;
			edges.push_back(e);
			e.Swap();
			edges.push_back(e);
		}
		printf("%d\n",solve(s,d,c));
	}
	return 0;
}