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>

#define inf 1000000000

using namespace std;

int n,m;
int road[101][101];

class sint{
	public:
	int iti,now,tick;
	sint(){}
	sint(int a,int b,int c){iti=a;now=b;tick=c;}
	bool operator < (const sint &a)const{
		return now>a.now;
	}
};

int dike(int cick,int st,int en){
	priority_queue<sint> state;
	
	int sima[101][11];
	int visit[101][11];
	for(int i=0;i<101;i++){
		for(int j=0;j<11;j++){
			sima[i][j]=inf;
			visit[i][j]=0;
		}
	}
	state.push(sint(st,0,0));
	sima[st][0]=0;
	
	while(1){
		sint u=state.top();
		state.pop();
		
		visit[u.iti][u.tick]=1;
		if(u.iti==en){
			return u.now;
		}
		
		/*
		for(int i=0;i<cick;i++){
			for(int j=0;j<n;j++){
				printf("%d ",sima[j][i]);
			}puts("");
		}puts("");
		*/
		for(int i=1;i<=n;i++){
			if(road[u.iti][i]==inf || visit[i][u.tick]==1) continue;
			
			if(sima[u.iti][u.tick]+road[u.iti][i]<sima[i][u.tick]){
				sima[i][u.tick]=sima[u.iti][u.tick]+road[u.iti][i];
				state.push(sint(i,sima[i][u.tick],u.tick));
			}
			
			if(u.tick<cick){
				if(sima[u.iti][u.tick]+road[u.iti][i]/2 < sima[i][u.tick+1]){
					sima[i][u.tick+1]=sima[u.iti][u.tick]+road[u.iti][i]/2;
					state.push(sint(i,sima[i][u.tick+1],u.tick+1));
				}
			}
		}
	}
	
	return st;
}

int main(){
	while(1){
		int c,s,d;
		cin>>c>>n>>m>>s>>d;
		if(n==0)break;
		for(int i=0;i<101;i++){
			for(int j=0;j<101;j++){
				road[i][j]=inf;
			}
		}
		for(int i=0;i<m;i++){
			int a,b,e;
			cin>>a>>b>>e;
			road[a][b]=road[b][a]=e;
		}
		
		printf("%d\n",dike(c,s,d));
	}
}

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

#define INF 100000000

struct edge {
	int to;
	int f;
	edge(int to_, int f_) {
		to = to_; f = f_;
	}
	edge(){}
};
struct status {
	int vertex;
	int cost;
	int c;
	status(int vertex_, int cost_, int c_) {
		vertex = vertex_; cost = cost_; c = c_;
	}
	status(){}
	bool operator<(const status & obj) const {
		if(this->c != obj.c)
			return this->c < obj.c;
		return this->cost > obj.cost;
	}
};

int main() {
	while(true) {
		int c, n, m, s, d;
		cin >> c >> n >> m >> s >> d;
		if(!(c || n || m || s || d))
			break;
		s--; d--;
		vector<vector<edge> > v(n);
		for(int i = 0; i < m; i++) {
			int a, b, f;
			cin >> a >> b >> f;
			a--; b--;
			v[a].push_back(edge(b,f));
			v[b].push_back(edge(a,f));
		}
		priority_queue<status> q;
		int cost[128][16];
		for(int i = 0; i < 128; i++)
			for(int j = 0; j < 16; j++)
				cost[i][j] = INF;
		q.push(status(s, 0, c));
		while(!q.empty()) {
			status cur;
			cur = q.top(); q.pop();

			if(cost[cur.vertex][cur.c] == INF) {
				cost[cur.vertex][cur.c] = cur.cost;
				for(int i = 0; i < v[cur.vertex].size(); i++) {
					if(cost[v[cur.vertex][i].to][cur.c] == INF) {
						q.push(status(v[cur.vertex][i].to, v[cur.vertex][i].f + cur.cost, cur.c));
					}
					if(cur.c > 0 && cost[v[cur.vertex][i].to][cur.c-1] == INF) {
						q.push(status(v[cur.vertex][i].to, v[cur.vertex][i].f / 2 + cur.cost, cur.c - 1));
					}
				}
			}
		}

		int ret = INF;
		for(int i = 0; i <= m; i++) {
			ret = min(ret, cost[d][i]);
		}
		cout << ret << endl;
	}
}

C++: //Solution for aoj:0212 Highway Express Bus
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
using namespace std;
typedef pair<int, int>P;


struct S {
	int cost, to, num;
	S(int c, int t, int n) : cost(c), to(t), num(n){}
	bool operator>(const S &s) const {
		return cost > s.cost;
	}
};

const int INF = 1 << 30;
int c, n, m, s, d, ans;
int tocost[101][11];
vector<P> town[101];
priority_queue<S, vector<S>, greater<S> > pq;


void dijkstra(){
	while (!pq.empty()){
		S a = pq.top();
		pq.pop();
		for (int i = 0; i < town[a.to].size(); i++){
			int tt = town[a.to][i].first, cc = town[a.to][i].second;
			if (tocost[tt][a.num] > cc + a.cost){
				tocost[tt][a.num] = cc + a.cost;
				pq.push({ cc + a.cost, tt, a.num });
			}
			if (a.num>0&&tocost[tt][a.num-1] > cc/2 + a.cost){
				tocost[tt][a.num-1] = cc/2 + a.cost;
				pq.push({ cc/2 + a.cost, tt, a.num-1 });
			}
		}
	}
}
	int main(){
		while (cin >> c >> n >> m >> s >> d&&c&&n&&m&&s){
			for (int i = 0; i < 101; i++)
				fill(tocost[i], tocost[i] + 11, INF);
			tocost[s][c] = 0;
			ans = INF;
			while (pq.size())
				pq.pop();
			for (int i = 0; i < 101; i++)
				town[i].clear();
			for (int i = 0; i < m; i++){
				int a, b, c;
				cin >> a >> b >> c;
				town[a].push_back({ b, c });
				town[b].push_back({ a, c });
			}
			pq.push({ 0, s, c });
			dijkstra();
			for (int i = 0; i <= c; i++)
				ans = min(ans, tocost[d][i]);
			cout << ans << endl;
		}
		return 0;
	}