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

using namespace std;
typedef pair<int, int> Pi;
typedef pair<int, Pi> Ti;

int c, n, m, s, d;
vector<vector<Pi>> edge;

int djk(int s, int g) {
	int d[100 + 16][11];
	for (int i = 0; i < n; i++)for (int j = 0; j <= c; j++)d[i][j] = 1000000000;
	d[s][c] = 0;
	priority_queue<Ti, vector<Ti>, greater<Ti>> pq;
	pq.push(make_pair(0, make_pair(s, c)));
	while (pq.size()) {
		Ti tmp = pq.top(); pq.pop();
		int N = tmp.second.first, ticket = tmp.second.second;
		if (d[N][ticket] < tmp.first)continue;
		for (int i = 0; i < edge[N].size(); i++) {
			int to = edge[N][i].first, cost = edge[N][i].second;
			if (ticket > 0) {
				if (d[to][ticket - 1] > d[N][ticket] + cost / 2) {
					d[to][ticket - 1] = d[N][ticket] + cost / 2;
					pq.push(make_pair(d[to][ticket - 1], make_pair(to, ticket - 1)));
				}
			}
			if (d[to][ticket] > d[N][ticket] + cost) {
				d[to][ticket] = d[N][ticket] + cost;
				pq.push(make_pair(d[to][ticket], make_pair(to, ticket)));
			}
		}
	}
	int ans = 1000000000;
	for (int i = 0; i <= c; i++)ans = min(ans, d[g][i]);
	return ans;
}

int main() {
	while (cin >> c >> n >> m >> s >> d, c + n + m + s + d) {
		s--, d--;
		edge.resize(n);

		for (int i = 0; i < m; i++) {
			int a, b, f;
			cin >> a >> b >> f, a--, b--;
			edge[a].push_back(make_pair(b, f));
			edge[b].push_back(make_pair(a, f));
		}
		cout << djk(s, d) << endl;
		edge.clear();
	}
	return 0;
}

C++: #include<queue>
#include<cstdio>
#include<algorithm>

#define	mp	make_pair

using namespace std;

typedef	pair<int,int>	pii;

const int inf=1<<29;
int adj[100][100],memo[100][11];
bool visited[100][11];

int main(){
	for(int c,m,n,src,dst;scanf("%d%d%d%d%d",&c,&m,&n,&src,&dst),c;){
		src--,dst--;
		for(int i=0;i<n;i++)for(int j=0;j<n;j++)	adj[i][j]=(i==j?0:inf);
		for(int i=0;i<n;i++)for(int j=0;j<=c;j++)	memo[i][j]=inf,visited[i][j]=false;
		for(int i=0;i<m;i++){
			int a,b,fee;	scanf("%d%d%d",&a,&b,&fee);
			a--,b--;
			adj[a][b]=adj[b][a]=fee;
		}

		memo[src][0]=0;
		priority_queue< pair<int,pii> > pq;	pq.push(mp(0,mp(src,0)));
		while(!pq.empty()){
			pair<int,pii> a=pq.top();	pq.pop();
			int fee=-a.first;
			int u=a.second.first;
			int tic=a.second.second;
			if(u==dst)	break;

			if(visited[u][tic])	continue;
			visited[u][tic]=true;

			for(int v=0;v<n;v++){
				if(!visited[v][tic] && fee+adj[u][v]<memo[v][tic]){
					memo[v][tic]=fee+adj[u][v];
					pq.push(mp(-memo[v][tic],mp(v,tic)));
				}
				if(tic<c && !visited[v][tic+1] && fee+adj[u][v]/2<memo[v][tic+1]){
					memo[v][tic+1]=fee+adj[u][v]/2;
					pq.push(mp(-memo[v][tic+1],mp(v,tic+1)));
				}
			}
		}

		int feemin=inf;
		for(int i=0;i<=c;i++)	feemin=min(feemin,memo[dst][i]);
		printf("%d\n",feemin);
	}

	return 0;
}

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

using namespace std;

const int INF = 10000000;

int solve( int city[101][101], int s, int d, int c, int n ){
	int dist[11][101];
	int history[101];

	for( int i = 0;i < 11;i++ ){
		for( int j = 0;j < 101;j++ ){
			dist[i][j] = INF;
		}
	}

	for( int i = 0;i < 101;i++ ){
		history[i] = 0;
	}

	for( int i = 0;i < 11;i++ ) dist[i][s] = 0;

	typedef pair<int,int> data;
	typedef pair<int,data> graph;
	priority_queue<graph,vector<graph>,greater<graph> > q;

	q.push( graph( 0, data( s, c ) ) );

	while( !q.empty() ){
		graph a = q.top();
		int u = a.second.first;
		int uc = a.second.second;
		q.pop();
		history[u] = 1;

		for( int i = 1;i <= n;i++ ){
			if( city[u][i] == INF || history[i] ) continue;

			if( dist[uc][i] > dist[uc][u] + city[u][i] ){
				dist[uc][i] = dist[uc][u] + city[u][i];
				q.push( graph( dist[uc][i], data( i, uc ) ) );
			}

			if( uc && dist[uc - 1][i] > dist[uc][i] + city[u][i] / 2 ){
				dist[uc - 1][i] = dist[uc][u] + city[u][i] / 2;
				q.push( graph( dist[uc - 1][i], data( i, uc - 1 ) ) );
			}
		}
	}
	int answer = INF;
	for( int i = 0;i < 11;i++ ) answer = min( dist[i][d], answer );
	return answer;

}

int main(int argc, char const* argv[])
{
	int c,n,m,s,d;
	int city[101][101];

	while( cin >> c >> n >> m >> s >> d && c != 0 ){
		int a,b,f;
		for( int i = 0;i < 101;i++ ){
			for( int j = 0;j < 101;j++ ){
				city[i][j] = INF;
			}
		}
		for( int i = 0;i < m;i++ ){
			cin >> a >> b >> f;
			city[a][b] = f;
			city[b][a] = f;
		}

		cout << solve( city, s, d, c, n ) << endl;
	}

	return 0;
}