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
}

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)
		for len(pq) != 0 {
			now := heap.Pop(&pq).(*Node)
			if now.NowPosition == d {
				fmt.Println(now.Amount)
				break
			}
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				heap.Push(&pq, next)
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					heap.Push(&pq, next)
				}
			}
		}
	}
}

C++: // AOJ 0212
#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 << 29;

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, 100 )
			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 <queue>

using namespace std;

struct NODE {
	int now, cost, ticket;
	NODE(int now, int cost, int ticket) : now(now), cost(cost), ticket(ticket) {}
	NODE () {}
};

bool operator < (const NODE &a, const NODE &b)
{
	return a.cost > b.cost;
}

int main(void)
{
	int c, n, m, s, d;
	while (cin >> c >> n >> m >> s >> d, n){
		vector <NODE> edge[150];
		int a, b, f;
		for (int i = 0; i < m; i++){
			cin >> a >> b >> f;
			edge[a].push_back(NODE(b, f, -1));
			edge[b].push_back(NODE(a, f, -1));
		}

		bool visited[150][20] = {};
		priority_queue <NODE> Q;
		Q.push(NODE(s, 0, c));
		while (Q.size()){
			NODE q = Q.top();
			Q.pop();
			if (visited[q.now][q.ticket]) continue;
			visited[q.now][q.ticket] = true;
			if (q.now == d){
				cout << q.cost << endl;
				break;
			}
			for (int i = 0; i < edge[q.now].size(); i++){
				Q.push(NODE(edge[q.now][i].now, q.cost + edge[q.now][i].cost, q.ticket));
				if (q.ticket){
					Q.push(NODE(edge[q.now][i].now, q.cost + (edge[q.now][i].cost / 2), q.ticket - 1));
				}
			}
		}
	}

	return 0;
}

C++: //Solution for aoj:0212 Highway Express Bus
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
using namespace std;
typedef pair<int, int>P;


struct S {
	int cost, to, num;
	S(int c, int t, int n) : cost(c), to(t), num(n){}
	bool operator>(const S &s) const {
		return cost > s.cost;
	}
};

const int INF = 1 << 29;
int c, n, m, s, d, ans;
int tocost[101][11];
vector<P> town[501];
priority_queue<S, vector<S>, greater<S> > pq;


void dijkstra(){
	while (!pq.empty()){
		S a = pq.top();
		pq.pop();
		for (int i = 0; i < town[a.to].size(); i++){
			int tt = town[a.to][i].first, cc = town[a.to][i].second;
			if (tocost[tt][a.num] > cc + a.cost){
				tocost[tt][a.num] = cc + a.cost;
				pq.push({ cc + a.cost, tt, a.num });
			}
			if (a.num>0&&tocost[tt][a.num-1] > cc/2 + a.cost){
				tocost[tt][a.num-1] = cc/2 + a.cost;
				pq.push({ cc/2 + a.cost, tt, a.num-1 });
			}
		}
	}
}
	int main(){
		while (cin >> c >> n >> m >> s >> d&&c&&n&&m&&s){
			for (int i = 0; i < 101; i++)
				fill(tocost[i], tocost[i] + 11, INF);
			tocost[s][c] = 0;
			ans = INF;
			while (pq.size())
				pq.pop();
			for (int i = 0; i < n; i++)
				town[i].clear();
			for (int i = 0; i < m; i++){
				int a, b, c;
				cin >> a >> b >> c;
				town[a].push_back({ b, c });
				town[b].push_back({ a, c });
			}
			pq.push({ 0, s, c });
			dijkstra();
			for (int i = 0; i <= c; i++)
				ans = min(ans, tocost[d][i]);
			cout << ans << endl;
		}
		return 0;
	}

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