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 <cstring>
using namespace std;
int c, n, m, s, d;

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

int main () {
	while (cin >> c >> n >> m >> s >> d, c || n || m || s || d) {
		memset(field, 0, sizeof(field));
		memset(visited, 0, 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 && (current.second.first == 0 || (c > n && current.second.first == c - n))) {
				cout << current.first * 10 << endl;
				break;
			}
			visited[current.second.first][current.second.second] = 1;
			for (int i = 1; i <= n; i++) {
				if (field[current.second.second][i] > 0) {
					if (!visited[current.second.first][i]) {
						q.push(make_pair(current.first + field[current.second.second][i], make_pair(current.second.first, i)));
					}
					if (current.second.first > 0 && !visited[current.second.first - 1][i]) {
						q.push(make_pair(current.first + field[current.second.second][i] / 2, make_pair(current.second.first - 1, i)));
					}
				}
			}
		}
	}
	return 0;
}

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

const int INF = 1e9;

//<最小コスト, 町番号>
typedef pair<int, int> P;
struct edge{int to, cost;};
int c, n, m, s, dist;
vector<edge> G[100];
//割引券が残りiの時のj地点における最小コスト
int d[10][100];

void dijkstra(int s, int a){
	priority_queue<P, vector<P>, greater<P> > Q;
	for(int i = 0; i < n; i++) d[a][i] = INF;
	d[a][s] = 0;
	Q.push(P(0, s));

	while(!Q.empty()){
		P p = Q.top(); Q.pop();
		int v = p.second;

		if(d[a][v] < p.first)	continue;
		for(int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			
			//割引券を使った時と使ってない時でよりコストが小さい時をdmに代入
			int dm;
			if(a == 0)	dm = d[a][v] + e.cost;
			else dm = min(d[a][v] + e.cost, d[a-1][v] + e.cost / 2);

			if(d[a][e.to] > dm){
				d[a][e.to] = dm;
				Q.push(P(d[a][e.to], e.to));
			}
		}
	}
}

int main(void){
	while(true){
		cin >> c >> n >> m >> s >> dist;
		s--; dist--;
		if(!c)	break;

		edge e;
		for(int i = 0; i < m; i++){
			int a, b, f;
			cin >> a >> b >> f;
			a--; b--;
			e.to = b; e.cost = f;
			G[a].push_back(e);
			e.to = a;
			G[b].push_back(e);
		}

		int ans = INF;

		for(int i = 0; i <= c; i++){
			dijkstra(s, i);
		}

		cout << d[c][dist] << endl;

		for(int i = 0; i < 100; i++) G[i].clear();
	}

  return 0;
}

C++: #include <map>
#include <vector>
#include <cstdio>
#include <cstring>
using namespace std;
int cost[101][11];
int main(){
	int c,N,m,s,d,i,j,k,x;
	for(;scanf("%d%d%d%d%d",&c,&N,&m,&s,&d),N;){
		vector<map<int,int> >dist(N+1);
		memset(cost,99,sizeof(cost));
		for(k=0;k<m;k++){
			scanf("%d%d%d",&i,&j,&x);dist[i][j]=dist[j][i]=x;
		}
		for(i=0;i<=c;i++)cost[s][i]=0;
		for(;~c;c--){
			vector<bool>used(N+1);
			for(;;){ //dijkstra
				int m=1e9;
				for(i=1;i<=N;i++)if(!used[i]&&m>cost[i][c])m=cost[i][c];
				if(m==1e9)break;
				for(j=1;j<=N;j++)if(m==cost[j][c]){
					map<int,int>::iterator it=dist[j].begin();
					for(used[j]=1;it!=dist[j].end();it++){
						if(cost[it->first][c]>it->second+cost[j][c])cost[it->first][c]=it->second+cost[j][c];
						if(c&&cost[it->first][c-1]>it->second/2+cost[j][c])cost[it->first][c-1]=it->second/2+cost[j][c];
					}
				}
			}
		}
		printf("%d\n",cost[d][0]);
	}
}