Go: package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

const INF = 0x7FFFFFFF

var pass [][]int

func main() {
	for scanner.Scan() {
		pass = make([][]int, 200)
		for i := range pass {
			pass[i] = make([]int, 200)
		}
		buf := strings.Split(scanner.Text(), " ")
		c, _ := strconv.Atoi(buf[0])
		n, _ := strconv.Atoi(buf[1])
		m, _ := strconv.Atoi(buf[2])
		s, _ := strconv.Atoi(buf[3])
		d, _ := strconv.Atoi(buf[4])
		if c == 0 && n == 0 && m == 0 && s == 0 && d == 0 {
			break
		}
		s--
		d--
		for i := 0; i < 200; i++ {
			for j := 0; j < 200; j++ {
				pass[i][j] = INF
			}
		}
		for i := 0; i < 200; i++ {
			pass[i][i] = 0
		}
		for i := 0; i < m; i++ {
			scanner.Scan()
			buf_ := strings.Split(scanner.Text(), " ")
			a, _ := strconv.Atoi(buf_[0])
			b, _ := strconv.Atoi(buf_[1])
			f, _ := strconv.Atoi(buf_[2])
			a--
			b--
			pass[a][b] = f
			pass[b][a] = f
		}
		fmt.Println(dijkstra(s, d, c, n))
	}
}

func dijkstra(s, g, c, n int) float64 {
	d := make([][]float64, 200)
	used := make([][]bool, 200)
	for i := 0; i < 200; i++ {
		d[i] = make([]float64, 20)
		used[i] = make([]bool, 20)
	}
	for i := range d {
		for j := range d[i] {
			d[i][j] = INF
		}
	}
	d[s][c] = 0
	for {
		v := -1
		w := -1
		for u := 0; u < n; u++ {
			for i := 0; i < c+1; i++ {
				if !used[u][i] && (v == -1 || d[u][i] < d[v][w]) {
					v = u
					w = i
				}
			}
		}
		if v == -1 {
			break
		}
		used[v][w] = true
		for u := 0; u < n; u++ {
			d[u][w] = math.Min(d[u][w], d[v][w]+float64(pass[v][u]))
			if w-1 >= 0 && pass[v][u] != INF {
				d[u][w-1] = math.Min(d[u][w-1], d[v][w]+(float64(pass[v][u]/2.0)))
			}
		}
	}
	ret := float64(INF)
	for i := 0; i < c+1; i++ {
		ret = math.Min(ret, d[g][i])
	}
	return ret
}

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

using namespace std;

#define MAX_N 101
#define INF 1 << 28

struct edge_t {
    int from, to, cost;
    edge_t(int from=0, int to=0, int cost=0) :
        from(from), to(to), cost(cost) {}
};

struct state_t {
    int city;   // 現在地
    int coupon; // 残り割引券枚数
    int cost;   // 現在地までにかかった金額
    state_t(int city=0, int coupon=0, int cost=0) :
        city(city), coupon(coupon), cost(cost) {}
    bool operator>(const state_t &o) const {
        return cost == o.cost ? coupon < o.coupon : cost > o.cost;
    }
    bool operator<(const state_t &o) const {
        return cost == o.cost ? coupon > o.coupon : cost < o.cost;
    }
};

int c, n, m, s, d;
vector<edge_t> graph[MAX_N];

int dijkstra() {
    int cost[n+1][c+1];
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= c; j++)
            cost[i][j] = INF;

    priority_queue<state_t, vector<state_t>, greater<state_t> > q;

    cost[s][c] = 0;

    q.push(state_t(s, c, 0));

    while (!q.empty()) {
        state_t p = q.top(); q.pop();

        for (int i = 0; i < graph[p.city].size(); i++) {
            edge_t e = graph[p.city][i];

            // クーポン券を使わないとき
            if (cost[e.to][p.coupon] > cost[e.from][p.coupon] + e.cost) {
                cost[e.to][p.coupon] = cost[e.from][p.coupon] + e.cost;
                q.push(state_t(e.to, p.coupon, cost[e.to][p.coupon]));
            }

            // クーポン券を使うとき
            if (p.coupon > 0) {
                if (cost[e.to][p.coupon-1] > cost[e.from][p.coupon] + e.cost / 2) {
                    cost[e.to][p.coupon-1] = cost[e.from][p.coupon] + e.cost / 2;
                    q.push(state_t(e.to, p.coupon-1, cost[e.to][p.coupon-1]));
                }
            }
        }
    }

    int min_cost = INF;
    for (int i = 0; i <= c; i++) 
        min_cost = min(min_cost, cost[d][i]);
    return min_cost;
}

int main() {
    while (cin >> c >> n >> m >> s >> d) {
        if (c == 0 && n == 0 && m == 0 && s == 0 && d == 0) break;
        for (int i = 0; i <= n; i++) graph[i].clear();
        for (int i = 0; i < m; i++) {
            int a, b, f; cin >> a >> b >> f;
            graph[a].push_back(edge_t(a, b, f));
            graph[b].push_back(edge_t(b, a, f));
        }
        cout << dijkstra() << endl;
    }
    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 << 30;
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(S( 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(S( 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(P( b, c ));
				town[b].push_back(P( a, c ));
			}
			pq.push(S( 0, s, c ));
			dijkstra();
			for (int i = 0; i <= c; i++)
				ans = min(ans, tocost[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 = 1 << 30;

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

int dijkstra( int s )
{
	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( s ) );
	}

	return 0;
}