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

using namespace std;

#define PII pair<int,int>
#define PPI pair<int,PII>

#define INF 1000000000

int c;	//øÌ	   1 <= c <=    10
int n;	//¬Ì		   2 <= n <=   100
int m;	//oXÌHü	   1 <= m <=   500
int s,g;//X^[gAS[n_
//int cost[512][512];		//[i][j]Åi©çjÖÌRXg
vector<PII> cost[512];		//firstªto secondªRXg

int d[128][16];

priority_queue< PPI, vector<PPI>, greater<PPI> > Q;
//first ÅZ£ ,second.first ¸_,second.second øðgÁ½


void dijkstra(int s){
	for(int i = 0; i < 128; i++){
		for(int j = 0; j < 16; j++){
			d[i][j] = INF;
		}
	}
	
	d[s][0] = 0;
	
	Q.push(PPI(0,PII(s,0)));
	
	while( !Q.empty() ){
		PPI ppi = Q.top();
		Q.pop();
		int v = ppi.second.first;
		int ca = ppi.second.second;
		
		if( d[v][ca] < ppi.first )continue;
		
		for(int i = 0; i < cost[v].size(); i++){
			PII a = cost[v][i];
			if(d[a.first][ca] > d[v][ca] + a.second ){
				d[a.first][ca] = d[v][ca] + a.second;
				Q.push(PPI(d[a.first][ca],PII(a.first,ca)));
			}
			if(ca < c){
				if(d[a.first][ca+1] > d[v][ca] + a.second/2 ){
					d[a.first][ca+1] = d[v][ca] + a.second/2;
					Q.push(PPI(d[a.first][ca+1],PII(a.first,ca+1)));
				}
			}
		}
	}
}


int main(void){
	
	while(scanf("%d%d%d%d%d", &c, &n, &m, &s, &g) && n != 0){
		int from, to, cos;
		int ans = INF;
		for(int i  =0; i < m; i++){
			scanf("%d%d%d", &from, &to, &cos);
			cost[from].push_back(PII(to,cos));
			cost[to].push_back(PII(from,cos));
		}
		
		dijkstra(s);
		
		for(int i = 0; i <= c; i++){
			ans = min(d[g][i],ans);
		}
		for(int i = 0; i < 512; i++){
			cost[i].clear();
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: // AOJ 0212
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#define rep(i,a) for( int i = 0; i != (a); ++i )

typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;

const int INF = 1 << 30;

int c, n, m, s, d;	
std::vector<P> G[100];
int dist[100][11];

int dijkstra()
{
	std::fill( (int*)dist, (int*)(dist+100), INF );
	dist[s][0] = 0;
	std::priority_queue<PP, std::vector<PP>, std::greater<PP> > pque;
	pque.push( PP( P( s, 0 ), 0 ) );
	while( !pque.empty() )
	{
		PP p = pque.top(); pque.pop();
		int v = p.first.first, cost = p.first.second, tic = p.second;

		if( dist[v][tic] < cost )
			continue;

		rep( i, G[v].size() )
		{
			P &e = G[v][i];

			if( tic < c && dist[e.first][tic+1] > dist[v][tic]+e.second/2 )
			{
				dist[e.first][tic+1] = dist[v][tic]+e.second/2;
				pque.push( PP( P( e.first, dist[e.first][tic+1] ), tic+1 ) );
			}

			if( dist[e.first][tic] > dist[v][tic]+e.second )
			{
				dist[e.first][tic] = dist[v][tic]+e.second;
				pque.push( PP( P( e.first, dist[e.first][tic] ), tic ) );
			}
		}
	}

	return *std::min_element( dist[d], dist[d]+11 );
}

int main()
{
	while( scanf( "%d%d%d%d%d", &c, &n, &m, &s, &d ), c|n|m|s|d )
	{
		--s; --d;
		rep( i, 101 )
			G[i].clear();

		rep( i, m )
		{
			int a, b, f;
			scanf( "%d%d%d", &a, &b, &f );
			--a; --b;
			G[a].push_back( P( b, f ) );
			G[b].push_back( P( a, f ) );
		}

		printf( "%d\n", dijkstra() );
	}

	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> > 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;
		queue<V> q;
		q.push(start);

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

			if(best[p.ticket][p.to] <= p.total) continue;
			best[p.ticket][p.to] = p.total;

			rep(i, n){
				if(fare[p.to][i] == INF ) 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){
			best[c][d] = min(best[c][d], best[i][d]);
		}

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

	return 0;
}