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

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, 0, 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;
			}
			visited[current.second.first][current.second.second] = current.first;
			for (int i = 1; i <= n; i++) {
				if (field[current.second.second][i] > 0) {
					if (current.first + field[current.second.second][i] < 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 && current.first + field[current.second.second][i] / 2 < 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 <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) string((s).rbegin(), (s).rend())
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int INF = 10000;


class V{
public:
	int total;
	int ticket;
	int to;
};
bool operator>(const V &lh, const V &rh){
	return (lh.total > rh.total);
}


int main(){
	while(1){

		int c, n, m, s, d;
		cin >> c >> n >> m >> s >> d;
		if(!(c+n+m+s+d))break;
		n++;
		vector<vector<int> > fare(n, vector<int>(n, INF));
		rep(i, m){
			int a, b, f;
			cin >> a >> b >> f;
			fare[a][b] = fare[b][a] = f;
		}

		vector<vector<int> > done(c+1, vector<int>(n, 0));	// 確定済みか
		vector<vector<int> > best(c+1, vector<int>(n, INF));	// 最短

		V start;
		start.total = 0;
		start.ticket = 0;
		start.to = s;

		priority_queue<V, vector<V>, greater<V> > q;
		q.push(start);

		while(!q.empty()){
			V p = q.top();
			q.pop();

			if(done[p.ticket][p.to] != 0) continue;
			done[p.ticket][p.to] = 1;
			best[p.ticket][p.to] = p.total;

			rep(i, n){
				if(fare[p.to][i] == INF ) continue;
				if(done[p.to][i]) continue;
				V next;
				next.total = p.total + fare[p.to][i];
				next.ticket = p.ticket;
				next.to = i;
				q.push(next);
				if(p.ticket < c){
					next.total = p.total + fare[p.to][i]/2;
					next.ticket = p.ticket+1;
					next.to = i;
					q.push(next);
				}
			}
		}
		//rep(i, c+1){
		//	rep(j, n){
		//		printf("%5d", best[i][j]);
		//	}
		//	cout << endl;
		//}

		cout << best[c][d] << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>

using namespace std;

#define INF 100000000

struct edge {
	int to, cost;
};

int main() {
	int c, n, m, s, d;
	while (cin >> c >> n >> m >> s >> d) {
		if (c == 0 && n == 0 && m == 0 && s == 0 && d == 0) {
			break;
		}
		vector<edge> ff[101];
		vector< vector<int> > ddd(n+1, vector<int>(n+1, INF));
		int a, b, f;
		for (int i = 0; i < m; i++) {
			cin >> a >> b >> f;
			edge e;
			e.to = b;
			e.cost = f;
			ff[a].push_back(e);
			e.to = a;
			ff[b].push_back(e);
			ddd[a][b] = ddd[b][a] = f;
		}
		for (int i = 1; i <= n; i++) {
			ddd[i][i] = 0;
		}
		for (int k = 1; k <= n; k++) {
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					ddd[i][j] = min(ddd[i][j], ddd[i][k]+ddd[k][j]);
				}
			}
		}
		vector<int> isd[101];
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (ddd[i][j] != INF) {
					isd[i].push_back(j);
				}
			}
		}
		vector< vector< vector<int> > > dp(n+1, vector< vector<int> >(n+1, vector<int>(c+1, INF)));
		for (int i = 1; i <= n; i++) {
			dp[s][i][0] = ddd[s][i];
		}
		for (int k = 1; k <= c; k++) {
			for (int p = 0; p < isd[s].size(); p++) {
				int pp = isd[s][p];
				dp[s][pp][k] = dp[s][pp][k-1];
				for (int i = 0; i < isd[s].size(); i++) {
					int ii = isd[s][i];
					
						for (int q = 0; q < ff[ii].size(); q++) {
							int qq = ff[ii][q].to;
							if (ddd[qq][pp] == INF) continue;
							if (dp[s][pp][k] > dp[s][ii][k-1]+(ff[ii][q].cost/2)+ddd[qq][pp]) {
								dp[s][pp][k] = dp[s][ii][k-1]+(ff[ii][q].cost/2)+ddd[qq][pp];
							}
						}
					
				}
			}
		}
		cout << dp[s][d][c] << endl;
	}
	return 0;
}