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
}

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 <iostream>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

const int inf = 1000001;

class St{
	public:
	int c, p, cost;
	St() {}
	St(int _c, int _p, int _cost): c(_c), p(_p), cost(_cost) {}
	
	bool operator>(const St& st) const{
		return cost > st.cost;
	}
};

int exdij(int a[101][101], int c, int n, int s, int t)
{
	int r = inf, mcost[101][11];
	bool vis[101][11];
	priority_queue<St, vector<St>, greater<St> > que;
	
	que.push(St(c, s, 0));
	fill(&vis[0][0], &vis[100][10], true);
	fill(&mcost[0][0], &mcost[100][10], inf);
	while(!que.empty()){
		St st = que.top();
		que.pop();
		if(st.p == t){
			r = st.cost;
			break;
		}
		if(!vis[st.p][st.c]){
			continue;
		}
		vis[st.p][st.c] = false;
		
		for(int i = 1; i <= n; i++){
			if(mcost[i][st.c] > st.cost+a[st.p][i]){
				mcost[i][st.c] = st.cost+a[st.p][i];
				que.push(St(st.c, i, mcost[i][st.c]));
			}
			if(st.c && mcost[i][st.c-1] > st.cost+a[st.p][i]/2){
				mcost[i][st.c-1] = st.cost+a[st.p][i]/2;
				que.push(St(st.c-1, i, mcost[i][st.c-1]));
			}
		}
	}
	
	return r;
}

int main()
{
	int c, n, m, s, d, t, u, f, a[101][101];
	
	while(cin>>c>>n>>m>>s>>d && (c+n+m+s+d)){
		fill(&a[0][0], &a[n][n], inf);
		for(int i = 0; i <= n; i++){
			a[i][i] = 0;
		}
		while(m--){
			cin >> t >> u >> f;
			a[t][u] = a[u][t] = f;
		}
		
		cout << exdij(a, c, n, s, d) << endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <tuple>
#include <queue>

using namespace std;

#define int long long

class Solver {
};

signed main() {
	while (true) {
		int c, n, m, s, d;
		cin >> c >> n >> m >> s >> d;
		s--;
		d--;
		if (c == 0)break;

		vector<vector<vector<tuple<int, int, int>>>> graph(c + 1,
			vector<vector<tuple<int, int, int>>>(n));

		for (int i = 0; i < m; i++) {
			int a, b, f;
			cin >> a >> b >> f;
			a--;
			b--;
			for (int i = 0; i <= c; i++) {
				graph[i][a].emplace_back(make_tuple(i, b, f));
				graph[i][b].emplace_back(make_tuple(i, a, f));
				if (i < c) {
					graph[i][a].emplace_back(make_tuple(i + 1, b, f/2));
					graph[i][b].emplace_back(make_tuple(i + 1, a, f/2));
				}
			}
		}

		priority_queue<tuple<int, int, int>> que;
		vector<vector<int>> dist(c + 1, vector<int>(n, 1e9));
		que.emplace(make_tuple(0, s, 0));
		while (que.size() > 0) {
			int cnt = get<0>(que.top());
			int pos = get<1>(que.top());
			int distance = get<2>(que.top());
			que.pop();
			if (dist[cnt][pos] <= distance)continue;

			dist[cnt][pos] = distance;
			for (int i = 0; i < graph[cnt][pos].size(); i++) {
				int cnt_t = get<0>(graph[cnt][pos][i]);
				int pos_t = get<1>(graph[cnt][pos][i]);
				int distance_t = get<2>(graph[cnt][pos][i]);
				distance_t += distance;

				if (dist[cnt_t][pos_t] <= distance_t)continue;

				que.emplace(make_tuple(cnt_t, pos_t, distance_t));
			}
		}

		int res = 1e9;
		for (int i = 0; i <= c; i++)res = min(res, dist[i][d]);
		cout << res << endl;
	}
}

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