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 <algorithm>
#include <numeric>
using namespace std;
#define NONE -1

// ÅZoHTõ - Ï
vector < vector <int> >	edges;
vector < vector <int> >	adj;

vector <int>	routes;
vector <int>	halfs;
int	kotae;
int	goal;
int coupon;

// ÅZoHTõ - Ö
void search_routes( int now )
{
	if ( kotae != NONE )
	{
		int half = accumulate( halfs.begin(), halfs.end(), 0 );
		if ( half >= kotae )
			return;
	}

	routes.push_back( now );
	if ( now == goal )
	{
		vector <int> r;
		for ( vector <int>::iterator it = routes.begin(); it != routes.end()-1; it++ )
		{
			r.push_back( edges[*(it+1)][*it] );
		}
		sort( r.rbegin(), r.rend() );
		for ( int i = 0; i < min( coupon, (int)r.size() ); i++ )
		{
			r[i] /= 2;
		}
		int sum = accumulate( r.begin(), r.end(), 0 );
		if ( kotae == NONE )
			kotae = sum;
		else
			kotae = min( sum, kotae );
	}
	else
	{
		for ( vector <int>::iterator it = adj[now].begin(); it != adj[now].end(); it++ )
		{
			if ( find( routes.begin(), routes.end(), *it ) == routes.end() )
			{
				halfs.push_back( edges[now][*it]/2 );
				search_routes( *it );
				halfs.pop_back();
			}
		}
	}
	routes.pop_back();
}

int main( void )
{
	// c: øÌ 1`10
	// n: oXªÂÈ®¬Ì 2`100
	// m: oXÌHü 1`500
	// s: start
	// d: goal
	int c, n, m, s, d;
	while ( cin >> c >> n >> m >> s >> d && c && n && m && s && d )
	{
		edges	=	vector < vector <int> >( 501, vector <int>(501, NONE) );
		adj		=	vector < vector <int> >( 501, vector <int>() );

		s--;
		d--;

		// ú»
		for ( int i = 0; i < m; i++ )
		{
			// f: a-bÔÌRXg
			int a, b, f;
			cin >> a >> b >> f;

			a--;
			b--;

			edges[a][b] = f;
			edges[b][a] = f;
			adj[a].push_back( b );
			adj[b].push_back( a );
		}

		routes	=	vector <int>(0);
		halfs	=	vector <int>(0);
		kotae	=	NONE;
		goal	=	d;
		coupon	=	c;

		search_routes( s );
		cout << kotae << endl;

	}

	return 0;
}

C++: #include <iostream>
#include <queue>
#include <climits>
#include <vector>
using namespace std;
typedef pair<pair<int,int>,int> NODE;
#define cost first.first
#define ticket first.second 
#define pos second
#define ppp(a,b,c) make_pair(make_pair(a,b),c)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<21)

int info[100][100];
int n;

int dijk(int a,int b,int c){
	priority_queue<NODE,vector<NODE>,greater<NODE> > que;
	int memo[100][11];
	rep(i,100)rep(j,11)memo[i][j] = INF;
	//rep(j,11)memo[a][j] = 0;
	
	que.push(ppp(0,c,a));
	while( !que.empty() ){
		NODE q = que.top();que.pop();
		
		if(memo[q.pos][q.ticket]<=q.cost)continue;
		
		if(q.pos == b)return q.cost;
		
		memo[q.pos][q.ticket] = q.cost;
		
		for(int i=0;i<n;i++){
			que.push(ppp(info[q.pos][i]+q.cost ,q.ticket,i));
			if(q.ticket)que.push(ppp(info[q.pos][i]/2+q.cost ,q.ticket-1,i));

		}
	}
	
	/*ツ個ゥツづつつゥツづァツづ按つゥツづつス*/
	return -1;
}
int main(){
	int c,m,s,d,a,b,f;
	while(cin >> c >> n >> m >> s >> d ,c ){
		s--;d--;
		rep(i,100)rep(j,100)info[i][j]=INF*2;
		
		for(int i=0;i<m;i++){
			cin >> a >> b >> f;
			a--;b--;
			info[a][b] = info[b][a] = f;
		}
		cout << dijk(s,d,c) << endl;
	}
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int c,n,m,s,d;
int rosen[101][101] = {-1};
int saiki(int p,vector<int> st,vector<bool> u){
    int ans = INF;
    if(p == d){
	sort(RALL(st));
	REP(i,c){
	    st[i] /= 2;
	}
	int sum = 0;
	REP(i,st.size()){
	    sum += st[i];
	}
	return sum;
    }
    FOR(i,1,n+1){
	if(!u[i] && rosen[p][i] > 0){
	    vector<int> temp = st;
	    vector<bool> utemp = u;
	    temp.PB(rosen[p][i]);
	    utemp[i] = true;
	    ans = min(ans,saiki(i,temp,utemp));
	}
    }
    return ans;
}

int main(){
    while(true){
	cin >> c >> n >> m >> s >> d;
	if(c==0&&n==0&&m==0&&s==0&&d==0) break;
	memset(rosen,-1,sizeof(rosen));
	REP(i,m){
	    int a,b,f;
	    cin >> a >> b >> f;
	    rosen[a][b] = f;
	    rosen[b][a] = f;
	}
	vector<bool>  used(n+1,false);
	vector<int> nanika;
	used[s] = true;
	cout << saiki(s, nanika ,used) << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int C, N, M, S, D;
vector<pii> g[100];
int d[11][100];

int main() {
	while (cin >> C >> N >> M >> S >> D, C || N || M || S || D) {
		S--; D--;
		REP(i, N) g[i].clear();
		
		REP(i, M) {
			int a, b, f;
			scanf("%d %d %d", &a, &b, &f);
			a--; b--;
			g[a].push_back(pii(b, f));
			g[b].push_back(pii(a, f));
		}
		
		fill(d[0], d[C + 1], INF);
		
		priority_queue<pii, vector<pii>, greater<pii> > pq[11];
		
		pq[0].push(pii(0, S));
		d[0][S] = 0;
		
		REP(i, C + 1) {
			while (!pq[i].empty()) {
				pii now = pq[i].top(); pq[i].pop();
				int u = now.se, cost = now.fi;
				REP(j, g[u].size()) {
					int v = g[u][j].fi, c = g[u][j].se;
					if (i < C && chmin(d[i + 1][v], cost + c / 2)) pq[i + 1].push(pii(cost + c / 2, v));
					if (chmin(d[i][v], cost + c)) pq[i].push(pii(cost + c, v));
				}
			}
		}
		
		int ans = INF;
		REP(i, C + 1) chmin(ans, d[i][D]);
		cout << ans << endl;
	}
	return 0;
}