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 <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;
}

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

const int INF = 100000000;
const int C_MAX = 10;
const int N_MAX = 100;

//街の情報 <残りの割引券, 街の番号>
typedef pair<int, int> T;
//地点情報 <最小コスト, <残りの割引券, 街の番号>>
typedef pair<int, T> P;

//c: チケットの枚数(1 <= c <= 10)
//n: バスをつなぐ町の数(2 <= n <= 100)
//m: バスの路線数(1 <= m <= 500)
//s: 出発地点
//d: 目的地
int c, n, m, s, d;
//cost[町の番号][残りの割引券] = 費用
int cost[N_MAX][C_MAX + 1];

//すでにコストの最適値が決定済みかどうか
bool flag[N_MAX][C_MAX + 1];

//町間の料金
int line[N_MAX][N_MAX];

typedef priority_queue<P, vector<P>, greater<P> > Q;
Q dp_q;

int dijkstra(){
	while(!dp_q.empty()){
		P p = dp_q.top(); dp_q.pop();
		T &t = p.second;

		//p.first: 最小コスト
		//t.first: 残りの割引券
		//t.second: 町番号

		//既に最適値なのかどうかを調べる
		if(flag[t.second][t.first])	continue;
		flag[t.second][t.first] = true;

		if(t.second == d){
			return p.first;
		}

		//すべての頂点に対して割引券を使ったか使ってないかを決める
		for(int i = 0; i < n; ++i){
			//割引券を使わなかった場合のiのコスト
			//(t.secondでの最小コスト + t.second -> iの料金)が割引券がt.firstの時の町iのコストより小さい
			//時にc[i][t.first]を更新
			if(cost[i][t.first] > p.first + line[t.second][i]){
				cost[i][t.first] = p.first + line[t.second][i];
				dp_q.push(P(p.first + line[t.second][i], T(t.first, i)));
			}

			//割引券を使った場合のiのコスト
			//(t.secondでの最小コスト + t.second -> iの料金の半分)が
			//割引券がt.first - 1の時の町iのコストより小さい時に
			//c[i][t.first - 1]を更新
			if(t.first > 0 && cost[i][t.first - 1] > p.first + line[t.second][i] / 2){
				cost[i][t.first-1] = p.first + line[t.second][i] / 2;
				dp_q.push(P(p.first + line[t.second][i] / 2, T(t.first - 1, i)));
			}
		}
	}

	return INF;
}

void solve(){
	for(int i = 0; i < N_MAX; ++i){
		for(int j = 0; j < C_MAX; ++j){
			cost[i][j] = INF;
			flag[i][j] = false;
		}
	}

	dp_q = Q();
	dp_q.push(P(0, T(c, s)));

	cout << dijkstra() << endl;
}

int main(void){
	int a, b, f;

	while(true){
		cin >> c >> n >> m >> s >> d;
		if(!c && !n && !m && !s && !d)	break;
		s--; d--;
		
		for(int i = 0; i < N_MAX; ++i){
			for(int j = 0; j < N_MAX; ++j){
				line[i][j] = INF;
			}
		}

		for(int i = 0; i < m; ++i){
			cin >> a >> b >> f;
			a--;	b--;
			line[a][b] = f;
			line[b][a] = f;
		}

		solve();
	}
  return 0;
}