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