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]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 <cstdio>
#include <queue>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
typedef pair<int,int> _P;
typedef pair<int,_P> P;
int main() {
	int c,n,m,s,d;
	int a,b,f;
	int i;
	int cost1[100][100],cost2[100][11];
	priority_queue<P,vector<P>,greater<P> > que;
	while(scanf("%d%d%d%d%d",&c,&n,&m,&s,&d),c) {
		fill(cost1[0],cost1[0]+100*100,1<<27);
		fill(cost2[0],cost2[0]+100*11,1<<27);
		for(i=0;i<m;i++) {
			scanf("%d%d%d",&a,&b,&f);
			cost1[a-1][b-1]=cost1[b-1][a-1]=min(cost1[a-1][b-1],f);
		}
		while(!que.empty()) que.pop();
		que.push(P(0,_P(s-1,0)));
		cost2[s-1][0]=0;
		while(!que.empty()) {
			P p=que.top();que.pop();
			if(cost2[p.second.first][p.second.second]<p.first) continue;
			for(i=0;i<n;i++) {
				if((p.first+cost1[p.second.first][i])<cost2[i][p.second.second]) {
					cost2[i][p.second.second]=p.first+cost1[p.second.first][i];
					que.push(P(cost2[i][p.second.second],_P(i,p.second.second)));
				}
				if(p.second.second+1<=c&&(p.first+cost1[p.second.first][i]/2)<cost2[i][p.second.second+1]) {
					cost2[i][p.second.second+1]=p.first+cost1[p.second.first][i]/2;
					que.push(P(cost2[i][p.second.second+1],_P(i,p.second.second+1)));
				}
			}
		}
		printf("%d\n",cost2[d-1][c]);
	}
}

C++: #include <iostream>
#include <queue>
#include <cstring>
using namespace std;
int c, n, m, s, d;

int field[101][101];
int visited[11][101];

int main () {
	while (cin >> c >> n >> m >> s >> d, c || n || m || s || d) {
		memset(field, 0x3, sizeof(field));
		memset(visited, 0x3, sizeof(visited));
		for (int i = 0; i < m; i++) {
			int a, b, f;
			cin >> a >> b >> f;
			field[a][b] = field[b][a] = f / 10;
		}
		priority_queue<pair<int, pair<int, int> >, vector<pair<int, pair<int, int> > >, greater<pair<int, pair<int, int> > > > q;
		q.push(make_pair(0, make_pair(c, s)));
		while (!q.empty()) {
			pair<int, pair<int, int> > current = q.top();
			q.pop();
			if (current.second.second == d) {
				cout << current.first * 10 << endl;
				break;
			}
			for (int i = 1; i <= n; i++) {
				if (current.first + field[current.second.second][i] < visited[current.second.first][i]) {
					int next = current.first + field[current.second.second][i];
					q.push(make_pair(next, make_pair(current.second.first, i)));
					visited[current.second.first][i] = next;
				}
				if (current.second.first > 0 && current.first + field[current.second.second][i] / 2 < visited[current.second.first - 1][i]) {
					int next = current.first + field[current.second.second][i] / 2;
					q.push(make_pair(next, make_pair(current.second.first - 1, i)));
					visited[current.second.first - 1][i] = next;
				}
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <functional>
#include <algorithm>
#include <cstring>

const int MAX_V = 100;
const int INF = 0x3f3f3f3f;

//??? T???cap??????rev????????°???????????§?????£???????????????
struct Edge{
	int to;
	int cost;
	Edge(int to_, int cost_) :to(to_), cost(cost_){}
};

std::vector<Edge > G[MAX_V]; //??£??\?????????

int d[11][MAX_V]; //[?????¨???????????±??????????????°][?????????]
int pre[MAX_V];

void AddEdge(int from, int to, int cost){
	G[from].push_back(Edge(to, cost));
}

void ClearEdge(){
	for (int i = 0; i < MAX_V; ++i) G[i].clear();
	memset(d, 0, sizeof(d));
	memset(pre, -1, sizeof(pre));
}

void Dijkstra(int c, int s){
	typedef std::pair<int, int> P; //first:???????????¢, second:????????????

	std::priority_queue<P, std::vector<P>, std::greater<P> > q;
	std::fill(d[c], d[c] + MAX_V, INF);
	memset(pre, -1, sizeof(pre));
	d[c][s] = 0;
	q.push(P(0, s));

	while (!q.empty()){
		P p = q.top(); q.pop();
		int from = p.second;
		if (d[c][from] < p.first) continue;
		for (Edge e : G[from]){
			int dmin;
			if (c == 0)
				dmin = d[c][from] + e.cost;
			else
				dmin = std::min(d[c][from] + e.cost, d[c - 1][from] + e.cost / 2);

			if (d[c][e.to] > dmin){
				d[c][e.to] = dmin;
				q.push(P(d[c][e.to], e.to));
				pre[e.to] = from;
			}
		}
	}
}

std::vector<int> GetPath(int t){
	std::vector<int> path;
	for (; t != -1; t = pre[t]) path.push_back(t);
	std::reverse(path.begin(), path.end());

	return path;
}

using namespace std;

int main(void){
	int c, n, m, s, g;
	while (1){
		cin >> c >> n >> m >> s >> g;
		if (c == n && n == m && m == s && s == g && g == 0) return 0;
		int a, b, f;
		for (int i = 0; i < n; ++i){
			cin >> a >> b >> f;
			AddEdge(a, b, f);
			AddEdge(b, a, f);
		}
		for (int i = 0; i <= c; ++i){
			Dijkstra(i, s);
		}
		cout << d[c][g] << endl;
		ClearEdge();
	}
}