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 <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;

template <typename T>
struct Edge { int src, dst; T cost;
    Edge(int dst, T cost) : src(-1), dst(dst), cost(cost) { }
    Edge(int src, int dst, T cost) : src(src), dst(dst), cost(cost) { }
};
template <typename T> using Edges = vector<Edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
template <typename T> using Matrix = vector<vector<T>>;

template <typename T>
vector<vector<T>> dijkstra(const WeightedGraph<T> &g, int s, int c) {
    const T INF = numeric_limits<T>::max();
    vector<vector<T>> dp(g.size(), vector<T>(c + 1, INF));
    using Pi = tuple<T, int, int>;
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;
    dp[s][c] = 0; que.emplace(dp[s][c], s, c);
    while (!que.empty()) {
        T cost; int v, cc; tie(cost, v, cc) = que.top(); que.pop();
        if (dp[v][cc] < cost) continue;
        for (auto &e: g[v]) {
            int nv = e.dst; T nc = e.cost;
            if (cc) {
                if (dp[nv][cc - 1] > dp[v][cc] + nc / 2) {
                    dp[nv][cc - 1] = dp[v][cc] + nc / 2;
                    que.emplace(dp[nv][cc - 1], nv, cc - 1);
                }
            }
            if (dp[nv][cc] <= dp[v][cc] + nc) continue;
            dp[nv][cc] = dp[v][cc] + nc;
            que.emplace(dp[nv][cc], nv, cc);
        }
    }
    return dp;
}

int main() {
    int c, n, m, s, d;
    while (cin >> c >> n >> m >> s >> d, s--, d--, n) {
        WeightedGraph<int> g(n);
        while (m--) {
            int a, b, f; cin >> a >> b >> f; a--, b--;
            /*if (a != d) */g[a].emplace_back(b, f);
            /*if (b != d) */g[b].emplace_back(a, f);
        }
        auto res = dijkstra(g, s, c)[d];
        cout << *min_element(res.begin(), res.end()) << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <list>
#include <queue>
#include <map>

static const int INF = 1 << 20;

using namespace std;

struct state
{
	int ticket, id, cost;
};

struct comparator : public binary_function<state, state, bool>
{
	bool operator() (const state &x, const state &y) const { return x.cost > y.cost; }
};

static bool det[11][101];
static int edges[101][101];

int main()
{
	int C,N,M,S,D;
	while(cin>>C>>N>>M>>S>>D,C|N|S|M|D)
	{
		for (int c = 0; c <= C; c++)
			for (int i = 1; i <= N; i++)
				det[c][i] = false;

		for (int i = 1; i <= N; i++)
			for (int j = 1; j <= N; j++)
				edges[i][j] = INF;

		for (int i = 0; i < M; i++)
		{
			int a,b,f;
			cin>>a>>b>>f;
			edges[a][b] = edges[b][a] = f;
		}

		state init = { C, S, 0 };

		// Dijkstra
		priority_queue<state, vector<state>, comparator> Q;
		Q.push(init);

		int min_cost = INF;
		while (!Q.empty())
		{
			state s = Q.top();
			Q.pop();
			if (det[s.ticket][s.id]) continue;
			det[s.ticket][s.id] = true;

			if (s.id == D) min_cost = min(min_cost, s.cost);

			for (int i = 1; i <= N; i++)
			{
				if (edges[s.id][i] == INF) continue;

				int cost = s.cost + edges[s.id][i];
				state s2 = { s.ticket, i, cost };

				if (!det[s2.ticket][s2.id]) Q.push(s2);

				if (s.ticket > 0)
				{
					cost = s.cost + edges[s.id][i] / 2;
					state s3 = { s.ticket - 1, i, cost };
					if (!det[s3.ticket][s3.id]) Q.push(s3);
				}
			}
		}
		cout << min_cost << endl;
	}
	return 0;
}

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 = 10000000;

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

int dijkstra( int s )
{
	rep( i, 101 )
		rep( j, 11 )
			dist[i][j] = 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( 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 ) );
			}
		}

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

			if( 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 ) );
			}
		}
	}

	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 )
	{
		rep( i, 101 )
			G[i].clear();

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

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

	return 0;
}