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 <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;

int c, n, m, S, D;

struct EDGE { int to, cost; };
vector<EDGE> g[100];

struct STATE
{
	int cost, now, num;
	
	bool operator<(const STATE t)const{
		return cost > t.cost;
	}
};

int d[100][11];

void init()
{
	for (int i = 0; i < 100; i++){
		g[i].clear();
	}
	for (int i = 0; i < 100; i++){
		for (int j = 0; j <= 10; j++){
			d[i][j] = INF;
		}
	}
}

void search(int s)
{	
	for (int i = 0; i <= 10; i++){
		d[s][i] = 0;
	}
	
	priority_queue<STATE, vector<STATE> > que;
	que.push({0, s, 0});
	while (!que.empty()){
		STATE st = que.top(); que.pop();
		if (d[st.now][st.num] < st.cost) continue;
		
		for (int i = 0; i < g[st.now].size(); i++){
			EDGE e = g[st.now][i];
			if (d[e.to][st.num] > d[st.now][st.num] + e.cost){
				d[e.to][st.num] = d[st.now][st.num] + e.cost;
				que.push({d[e.to][st.num], e.to, st.num});
			}
		}
		
		if (st.num == c) continue;
		
		for (int i = 0; i < g[st.now].size(); i++){
			EDGE e = g[st.now][i];
			if (d[e.to][st.num + 1] > d[st.now][st.num] + e.cost / 2){
				d[e.to][st.num + 1] = d[st.now][st.num] + e.cost / 2;
				que.push({d[e.to][st.num + 1], e.to, st.num + 1});
			}
		}
	}
}

int main()
{
	while (scanf("%d %d %d %d %d", &c, &n, &m, &S, &D), c){
		S--; D--;
		
		init();
		
		for (int i = 0; i < m; i++){
			int a, b, f;
			scanf("%d %d %d", &a, &b, &f);
			a--; b--;
			
			g[a].push_back({b, f});
			g[b].push_back({a, f});
		}
		
		search(S);
		int mini = INF;
		for (int i = 0; i <= c; i++) mini = min(mini, d[D][i]);
		printf("%d\n", mini);
	}
	
	return 0;
}

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

int calcCost(int c, int n, vector<int> path, vector<int> rt){
	priority_queue<int> costs;
	for(int i=1; i<rt.size(); i++){
		costs.push(path[rt[i]+n*rt[i-1]]);
	}
	int total = 0;
	while(costs.size() && c--){
		total += costs.top() / 2;
		costs.pop();
	}
	while(costs.size()){
		total += costs.top();
		costs.pop();
	}
	return total;
}
int main(){
	for(;;){
		int c,n,m,s,d;
		cin>>c>>n>>m>>s>>d;
		if(c+n+m+s+d==0) break;
		vector<pair<int, vector<int> > > route(n,make_pair(-1,vector<int>()));
		vector<int> path(n*n,-1);
		for(int i=0; i<m; i++){
			int a,b,f;
			cin>>a>>b>>f;
			path[--a+n*--b] = path[b+n*a] = f;
		}
		priority_queue<pair<int, vector<int> >, vector<pair<int, vector<int> > >, greater<pair<int, vector<int> > > > pq;
		pq.push(make_pair(0,vector<int>(1,s-1)));
		while(pq.size()){
			int cur = *(pq.top().second.rbegin());
			if(route[cur].first == -1){
				route[cur] = pq.top();
				for(int i=0; i<m; i++){
					if(route[i].first == -1 && path[i+n*cur] != -1){
						pair<int, vector<int> > copy = pq.top();
						copy.second.push_back(i);
						copy.first = calcCost(c,n,path,copy.second);
						pq.push(copy);
					}
				}
			}
			pq.pop();
		}
		cout<<route[d-1].first<<endl;
	}
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 29;
const double EPS = 1e-10;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
#define repD(i, n) for(int i = n; i >= 0; i--)

int cost[200][20];
vector<P> G[200];// to cost;

int main(){
	int c, n, m, s, d;
	int a, b, money;
	while(cin >> c  >> n >> m >> s >> d && (c || n || m || s || d)){
		rep(i, 200) G[i].clear();
		fill(&cost[0][0], &cost[199][19] + 1, INF);
		rep(i, m){
			cin >> a >> b >> money;
			G[a].push_back(P(b, money));
			G[b].push_back(P(a, money));
		}

		cost[s][c] = 0;
		priority_queue<PP, vector<PP>, greater<PP> > que;
		que.push(PP(0, P(s, c)));
		while(!que.empty()){
			PP pp = que.top();
			que.pop();
			int cos = pp.first;
			int pos = pp.second.first;
			int num = pp.second.second;
			if(pos == d){
				cout << cos << endl;
				break;
			}

			if(cos > cost[pos][num]) continue;
			rep(i,(int)G[pos].size()){
				int v = G[pos][i].first;
				int fee = G[pos][i].second;
				if(cost[v][num] > cos + fee){
					cost[v][num] = cos + fee;
					que.push(PP(cost[v][num], P(v, num)));
				}
				if(num > 0 && cost[v][num-1] > cos + fee / 2){
					cost[v][num-1] = cos + fee / 2;
					que.push(PP(cost[v][num-1], P(v, num-1)));
				}
			}
		}
	}
	return 0;
}