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

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

const int inf = 2e7;

typedef pair<int, int> P;

struct E{
	E(int t, int c) :
		t(t), c(c)
	{}

	int t, c;
};

int c, n, m, s, t;
vector<E> g[1100];
int d[1100];

int index(int i, int j){
	return i * (c + 1) + j;
}

int main(){
	while(1){
		scanf("%d%d%d%d%d", &c, &n, &m, &s, &t);
		--s;
		--t;
		if(c == 0){
			break;
		}
		rep(i, m){
			int a, b, k;
			scanf("%d%d%d", &a, &b, &k);
			--a;
			--b;
			rep(j, c + 1){
				g[index(a, j)].push_back(E(index(b, j), k));
				g[index(b, j)].push_back(E(index(a, j), k));
			}
			rep(j, c){
				g[index(a, j + 1)].push_back(E(index(b, j), k / 2));
				g[index(b, j + 1)].push_back(E(index(a, j), k / 2));
			}
		}

		fill_n(d, n * (c + 1), inf);

		priority_queue<P, vector<P>, greater<P> > q;
		d[index(s, c)] = 0;
		q.push(P(0, index(s, c)));
		while(!q.empty()){
			P v = q.top();
			q.pop();
			if(v.first > d[v.second]){
				continue;
			}
			rep(i, g[v.second].size()){
				E e = g[v.second][i];
				if(d[e.t] > v.first + e.c){
					d[e.t] = v.first + e.c;
					q.push(P(d[e.t], e.t));
				}
			}
		}

		printf("%d\n", *min_element(d + index(t, 0), d + index(t + 1, 0)));

		rep(i, n * (c + 1)){
			g[i].clear();
		}
	}
	return 0;
}

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