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<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9
typedef pair<mp,ll> mmp;

int main(){
    while(1){
	ll c,n,m,s,d;
	cin>>c>>n>>m>>s>>d;
	if(c==0)break;
	s--,d--;
	vector<vector<mp> > g(n);
	for(ll i=0;i<m;i++){
		ll a,b,f;
		cin>>a>>b>>f;
		a--;
		b--;
		g[a].push_back(mp(f,b) );
		g[b].push_back(mp(f,a) );
	}
	priority_queue<mmp,vector<mmp>,greater<mmp> > q;
	q.push(mmp(mp(0,0),s) );
	vector<vector<bool> > used(n,vector<bool>(c+1,false) );
	while(!q.empty() ){
		mmp now = q.top();
		q.pop();
		ll ncost = now.first.first;
		ll cc = now.first.second;
		ll nn = now.second;
		//cout<<nn<<' '<<cc<<endl;
		if(nn==d){
		    	//cout<<"ok"<<endl;
			cout<<ncost<<endl;
			break;
		}
		if(used[nn][cc]) continue;
		used[nn][cc] = true;
		for(ll i=0;i<g[nn].size();i++){
			ll next = g[nn][i].second;
			ll nec = g[nn][i].first;
			if(used[next][cc])continue;
			q.push(mmp(mp(ncost+nec,cc),next) );
			if(cc < c){
			    if(used[next][cc+1])continue;
				q.push(mmp(mp(ncost+nec/2,cc+1),next) );
			}
		}
	}


    }
	return 0;
}

C++: // AOJ 0212 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0212)
#include<cstdio>
#include<algorithm>
#include<limits>
#include<queue>
#include<vector>
#define rep(i,a) for(int i=0;i<(a);++i)

typedef std::pair<int, int> P;

const int MAX_N = 100, MAX_C = 10, INF = std::numeric_limits<int>::max()>>2;

struct St
{
	int v, dist, tick;

	St( int v, int dist, int tick )
	:	v(v), dist(dist), tick(tick)
	{}

	bool operator< ( const St &s ) const
	{ return dist > s.dist; }
};

int c, n, m, s, d;
std::vector<P> G[MAX_N];
int dp[MAX_N][MAX_C];

int main()
{
	while( scanf( "%d%d%d%d%d", &c, &n, &m, &s, &d ), c|n|m|s|d )
	{
		rep( i, n )
			G[i].clear();

		--s; --d;

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

		std::priority_queue<St> pque;
		pque.push( St( s, 0, c ) );
		
		rep( i, n ) rep( j, c+1 )
			dp[i][j] = INF;
		dp[s][c] = 0;
		
		while( !pque.empty() )
		{
			St st = pque.top(); pque.pop();
			int v = st.v, dist = st.dist, t = st.tick;

			if( dp[v][t] < dist )
				continue;

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

				if( dp[e.first][t] > dp[v][t]+e.second )
				{
					dp[e.first][t] = dp[v][t]+e.second;
					pque.push( St( e.first, dp[v][t]+e.second, t ) );
				}

				if( t && dp[e.first][t-1] > dp[v][t]+e.second/2 )
				{
					dp[e.first][t-1] = dp[v][t]+e.second/2;
					pque.push( St( e.first, dp[v][t]+e.second/2, t-1 ) );
				}
			}
		}

		printf( "%d\n", *std::min_element( dp[d], dp[d]+c+1 ) );
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <tuple>
#include <queue>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;
typedef tuple<int, int> P;
typedef tuple<ll, int, int> T;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

template<typename T>
void chmin(T &a, T b) {
    a = min(a, b);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int c, n, m, s, t;
    while (cin >> c >> n >> m >> s >> t, c + n + m + s + t) {
        s--;
        t--;
        vector<vector<P>> G(n);
        REP(i, 0, m) {
            int a, b, f;
            cin >> a >> b >> f;
            a--;
            b--;
            G[a].push_back(make_tuple(b, f));
            G[b].push_back(make_tuple(a, f));
        }
        const ll inf = 1LL << 60;
        auto dist = make_v(n, c + 1, inf);
        priority_queue<T, vector<T>, greater<T>> pq;
        // cost, ticket, vertex
        pq.emplace(0LL, c, s);
        REP(i, 0, c + 1) {
            dist[s][i] = 0;
        }
        while (pq.size()) {
            ll cost;
            int ticket, vertex;
            tie(cost, ticket, vertex) = pq.top();
            pq.pop();
            if (dist[vertex][ticket] < cost) continue;
            dist[vertex][ticket] = cost;
            for (auto p : G[vertex]) {
                int to, f;
                tie(to, f) = p;
                // use ticket
                if (ticket > 0 && dist[to][ticket - 1] > cost + f / 2) {
                    dist[to][ticket - 1] = cost + f / 2;
                    pq.emplace(dist[to][ticket - 1], ticket - 1, to);
                }
                // do not use ticket
                if (dist[to][ticket] > cost + f) {
                    dist[to][ticket] = cost + f;
                    pq.emplace(dist[to][ticket], ticket, to);
                }
            }
        }
        ll ans = inf;
        REP (i, 0, c + 1) {
            chmin(ans, dist[t][i]);
        }
        cout << ans << endl;
    }

    return 0;
}