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++: #include <iostream>
#include <map>
#include <queue>
#include <functional>
#include <algorithm>
using namespace std;

class Vertax
{
public:
	int n, d, c;
	Vertax(){}
	Vertax(int n, int d, int c) : n(n), d(d), c(c){}
};
bool operator > (Vertax v1, Vertax v2)
{
	if (v1.c == v2.c) return v1.d > v2.d;
	return v1.c > v2.c;
}
bool operator < (Vertax v1, Vertax v2)
{
	if (v1.c == v2.c) return v1.d < v2.d;
	return v1.c < v2.c;
}

typedef pair<int, int> p;
const int INF = 99999999;

int C, N, M, S, D; //??????????????°???????????°???????????°???????????°???????????°

int main()
{
	while (cin >> C >> N >> M >> S >> D, C + N + M + S + D)
	{
		vector<p> edge[101];
		priority_queue<Vertax, vector<Vertax>, greater<Vertax>> que;
		int distance[11][101];

		for (int i = 0; i < M; i++)
		{
			int a, b, f;
			cin >> a >> b >> f;
			edge[a].push_back(p(b, f));
			edge[b].push_back(p(a, f));
		}
		for (int i = 0; i <= C; i++)
		{
			for (int j = 0; j <= N; j++)
			{
				distance[i][j] = INF;
			}
		}
		
		Vertax start;
		start.n = S;
		start.d = 0;
		start.c = 0;
		que.push(start);
		distance[0][S] = 0;

		while (!que.empty())
		{
			int n = que.top().n;
			int d = que.top().d;
			int c = que.top().c;
			que.pop();

			for (int i = 0; i < edge[n].size(); i++)
			{
				int to = edge[n][i].first;
				int dis = edge[n][i].second;

				if (distance[c][to] > d + dis)
				{
					distance[c][to] = d + dis;
					que.push(Vertax(to, d + dis, c));
				}
				if (c < C && distance[c + 1][to] > d + (dis / 2))
				{
					distance[c + 1][to] = d + (dis / 2);
					que.push(Vertax(to, d + (dis / 2), c + 1));
				}
			}
		}

		int ans = INF;
		for (int i = 0; i <= C; i++)
		{
			ans = min(ans, distance[i][D]);
		}
		cout << ans << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

#define to first
#define dist second

const int INF = 1e9;

int main() {
    int c, n, m, s, d;
    while (cin >> c >> n >> m >> s >> d, c) {
        s--, d--;
        vector <vector <pair <int, int>>> G(n);
        rep (i, m) {
            int a, b, f;
            cin >> a >> b >> f;
            a--, b--;
            G[a].emplace_back(b, f);
            G[b].emplace_back(a, f);
        }

        // state -> (dist, now, num of ticket)
        using state = tuple <int, int, int>;
        priority_queue <state> que;
        vector <vector <int>> dp(n, vector <int> (c + 1, INF));
        dp[s][0] = 0;
        que.emplace(0, s, 0);

        while (!que.empty()) {
            state p = que.top(); que.pop();
            int dist, now, numOfTicket;
            tie(dist, now, numOfTicket) = p;

            for (auto & next : G[now]) {
                if (numOfTicket < c && dp[next.to][numOfTicket + 1] > dist + next.dist / 2) {
                    dp[next.to][numOfTicket + 1] = dist + next.dist / 2;
                    que.emplace(dp[next.to][numOfTicket + 1], next.to, numOfTicket + 1);
                }
                if (dp[next.to][numOfTicket] > dist + next.dist) {
                    dp[next.to][numOfTicket] = dist + next.dist;
                    que.emplace(dp[next.to][numOfTicket], next.to, numOfTicket);
                }
            }
        }
        int ans = INF;
        rep (i, c + 1) ans = min(ans, dp[d][i]);
        cout << ans << 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 )
{
	std::fill( (int*)dist, (int*)(dist+101), 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;
}