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++: //1.includes
#include<iostream>
#include<algorithm>
#include<queue>
#include<tuple>
#include<functional>
#include<vector>
using namespace std;

//2.defines
#define INF 1000000000000000000LL//10^18
#define MAX_N 1000
#define MAX_C 100
#define BLACK 2
#define GRAY 1
#define WHITE 0

//3.variables
priority_queue<tuple<long long, long long, long long>, vector<tuple<long long, long long, long long>>, greater<tuple<long long, long long, long long>>>Q;
long long dist[MAX_N][MAX_C];
long long color[MAX_N][MAX_C];
vector<pair<long long, long long>>X[MAX_N];
long long C, N, M, S, D, A, B, G;

//4.functions
void _memset() {
	for (int i = 0; i < MAX_N; i++) {
		for (int j = 0; j < MAX_C; j++) {
			dist[i][j] = 0;
			color[i][j] = WHITE;
		}
	}
	for (int i = 0; i < MAX_N; i++) {
		X[i].clear();
	}
	while (!Q.empty()) {
		Q.pop();
	}
}

long long dijkstra(long long s, long long t, long long u) {
	for (int i = 0; i < MAX_N; i++) {
		for (int j = 0; j < MAX_C; j++) {
			dist[i][j] = INF;
			color[i][j] = WHITE;
		}
	}
	Q.push(make_tuple(0, 0, s));
	dist[s][0] = 0;
	color[s][0] = GRAY;
	while (!Q.empty()) {
		tuple<long long, long long, long long> tup = Q.top();
		Q.pop();
		long long a1 = get<0>(tup);
		long long a2 = get<1>(tup);
		long long a3 = get<2>(tup);
		color[a3][a2] = BLACK;
		for (int i = 0; i < X[a3].size(); i++) {
			long long a4 = X[a3][i].first;
			long long a5 = X[a3][i].second;
			bool ok = true;
			if (color[a4][a2] == BLACK) { ok = false; }
			if (ok == true && a1 + a5 < dist[a4][a2]) {
				dist[a4][a2] = a1 + a5;
				color[a4][a2] = GRAY;
				Q.push(make_tuple(dist[a4][a2], a2, a4));
			}
			ok = true;
			if (color[a4][a2 + 1] == BLACK) { ok = false; }
			if (a2 + 1 > u) { ok = false; }
			if (ok == true && a1 + a5 / 2 < dist[a4][a2 + 1]) {
				dist[a4][a2 + 1] = a1 + a5 / 2;
				color[a4][a2 + 1] = GRAY;
				Q.push(make_tuple(dist[a4][a2 + 1], a2 + 1, a4));
			}
		}
	}
	long long minx = INF;
	for (int i = 0; i <= u; i++) {
		minx = min(minx, dist[t][i]);
	}
	return minx;
}

int main() {
	while (true) {
		_memset();
		cin >> C >> N >> M >> S >> D;
		if (C == 0 && N == 0 && M == 0 && S == 0 && D == 0) {
			break; //C=number of ticket
		}
		for (int i = 0; i < M; i++) {
			cin >> A >> B >> G;
			X[A].push_back(make_pair(B, G));
			X[B].push_back(make_pair(A, G));
		}
		cout << dijkstra(S, D, C) << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<queue>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int c,n,m,s,d; while(cin>>c>>n>>m>>s>>d,c){
		s--,d--;
		int a,b,f;
		int ad[n][n],cost[c+1][n];
		rep(i,n)rep(j,n)ad[i][j]=0;
		rep(i,c+1)rep(j,n)cost[i][j]=1<<20;
		rep(i,m)cin>>a>>b>>f,a--,b--,ad[a][b]=ad[b][a]=f;
		queue<pair<int,int> > F; F.push(make_pair(s,c));
		cost[c][s]=0;
		while(!F.empty()){
			int cnode=F.front().first,cc=F.front().second; F.pop();
			rep(i,n)if(ad[cnode][i]){
				if(cost[cc][i]>cost[cc][cnode]+ad[cnode][i])
				cost[cc][i]=cost[cc][cnode]+ad[cnode][i],
				F.push(make_pair(i,cc));
				if(cc>0&&cost[cc-1][i]>cost[cc][cnode]+ad[cnode][i]/2)
				cost[cc-1][i]=cost[cc][cnode]+ad[cnode][i]/2,
				F.push(make_pair(i,cc-1));
			}
		}
		int mi;rep(i,c+1)if(cost[i][d]!=1<<20){mi=i;break;}
		cout<<cost[mi][d]<<endl;
	}
	return 0;
}

C++: // 2010/12/29 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int c, n, m, s, d;
		cin >> c >> n >> m >> s >> d;
		if(c==0&&n==0&&m==0&&s==0&&d==0)
			break;

		int wgt[102][102];
		int hlf[102][102];
		for(int i=1; i<=n; i++)
			for(int j=1; j<=n; j++)
				if(i==j){
					wgt[i][j] = 0;
					hlf[i][j] = 20000;
				}
				else{
					wgt[i][j] = 20000;
					hlf[i][j] = 20000;
				}

		for(int i=0; i<m; i++){
			int a, b, f;
			cin >> a >> b >> f;
			wgt[a][b] = f;
			wgt[b][a] = f;
			hlf[a][b] = f/2;
			hlf[b][a] = f/2;
		}

		int djk[12][102];
		bool flg[12][102];
		for(int j=c; j>=0; j--)
			for(int i=1; i<=n; i++){
				djk[j][i] = 2000000;
				flg[j][i] = false;
			}
		djk[c][s] = 0;

		while(true){
			int j_min;
			int i_min;
			int w_min = 2000000;
			for(int j=0; j<=c; j++)
				for(int i=1; i<=n; i++)
					if((!flg[j][i])&&(djk[j][i]<w_min)){
						j_min = j;
						i_min = i;
						w_min = djk[j][i];
					}

			flg[j_min][i_min] = true;
			if(i_min==d){
				cout << djk[j_min][i_min] << endl;
				break;
			}

			for(int i=1; i<=n; i++)
				if(!flg[j_min][i])
					if(wgt[i_min][i]!=20000)
						if(djk[j_min][i]>djk[j_min][i_min]+wgt[i_min][i])
							djk[j_min][i] = djk[j_min][i_min]+wgt[i_min][i];
			if(j_min!=0)
				for(int i=1; i<=n; i++)
					if(!flg[j_min-1][i])
						if(hlf[i_min][i]!=20000)
							if(djk[j_min-1][i]>djk[j_min][i_min]+hlf[i_min][i])
								djk[j_min-1][i] = djk[j_min][i_min]+hlf[i_min][i];
		}
	}

	return 0;
}