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 <queue>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>

const int MAX_V = 101;
const int INF = 0x3f3f3f3f;

//??? T???cap??????rev????????°???????????§?????£???????????????
struct Edge{
	int to;
	int cost;
	Edge(int to_, int cost_) :to(to_), cost(cost_){}
};

std::vector<Edge > G[MAX_V]; //??£??\?????????

int d[11][MAX_V]; //[?????¨???????????±??????????????°][?????????]
int pre[MAX_V];

void AddEdge(int from, int to, int cost){
	G[from].push_back(Edge(to, cost));
}

void ClearEdge(){
	for (int i = 0; i < MAX_V; ++i) G[i].clear();
	memset(d, 0, sizeof(d));
	memset(pre, -1, sizeof(pre));
}

void Dijkstra(int c, int s){
	typedef std::pair<int, int> P; //first:???????????¢, second:????????????

	std::priority_queue<P, std::vector<P>, std::greater<P> > q;
	std::fill(d[c], d[c] + MAX_V, INF);
	memset(pre, -1, sizeof(pre));
	d[c][s] = 0;
	q.push(P(0, s));

	while (!q.empty()){
		P p = q.top(); q.pop();
		int from = p.second;
		if (d[c][from] < p.first) continue;
		for (Edge e : G[from]){
			int dmin;
			if (c == 0)
				dmin = d[c][from] + e.cost;
			else
				dmin = std::min(d[c][from] + e.cost, d[c - 1][from] + e.cost / 2);

			if (d[c][e.to] > dmin){
				d[c][e.to] = dmin;
				q.push(P(d[c][e.to], e.to));
				pre[e.to] = from;
			}
		}
	}
}

std::vector<int> GetPath(int t){
	std::vector<int> path;
	for (; t != -1; t = pre[t]) path.push_back(t);
	std::reverse(path.begin(), path.end());

	return path;
}

using namespace std;

int main(void){
	int c, n, m, s, g;
	while (1){
		cin >> c >> n >> m >> s >> g;
		if (c == n && n == m && m == s && s == g && g == 0) return 0;
		int a, b, f;
		for (int i = 0; i < m; ++i){
			cin >> a >> b >> f;
			AddEdge(a, b, f);
			AddEdge(b, a, f);
		}
		for (int i = 0; i <= c; ++i){
			Dijkstra(i, s);
		}
		cout << d[c][g] << endl;
		ClearEdge();
	}
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

int calcCost(int c, int n, vector<int> path, vector<int> rt){
	priority_queue<int> costs;
	for(int i=1; i<rt.size(); i++){
		costs.push(path[rt[i]+n*rt[i-1]]);
	}
	int total = 0;
	while(costs.size() && c--){
		total += costs.top() / 2;
		costs.pop();
	}
	while(costs.size()){
		total += costs.top();
		costs.pop();
	}
	return total;
}

int main(){
	for(;;){
		int c,n,m,s,d;
		cin>>c>>n>>m>>s>>d;
		if(c+n+m+s+d==0) break;
		vector<pair<int, vector<int>>> route(n,make_pair(-1,vector<int>(0)));
		vector<int> path(n*n,-1);
		for(int i=0; i<m; i++){
			int a,b,f;
			cin>>a>>b>>f;
			path[--a+n*--b] = path[b+n*a] = f;
		}
		priority_queue<pair<int, vector<int>>, vector<pair<int, vector<int>>>, greater<pair<int, vector<int>>>> pq;
		pq.push(make_pair(0,vector<int>(1,s-1)));
		while(pq.size()){
			int cur = *(pq.top().second.rbegin());
			if(route[cur].first == -1){
				route[cur] = pq.top();
				for(int i=0; i<m; i++){
					if(route[i].first == -1 && path[i+n*cur] != -1){
						auto copy = pq.top();
						copy.second.push_back(i);
						copy.first = calcCost(c,n,path,copy.second);
						pq.push(copy);
					}
				}
			}
			pq.pop();
		}
		cout<<route[d-1].first<<endl;
	}
}

C++: #include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0212

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX_VAL 110
#define MAX_C 12

typedef long long ll;
typedef pair<pair<ll,ll>,int> P;

struct edge{ll to, cost;};


int dijkstra(vector<edge> G[MAX_VAL], int s, int g, int V, int c){
	priority_queue<P,vector<P>,greater<P>> q;
	ll d[MAX_C][MAX_VAL];
	
	for(int i = 0; i < MAX_C; i++) for(int j = 0; j < MAX_VAL; j++) d[i][j] = INF;
	
	d[0][s] = 0;
	q.push(P(make_pair(0,s),0));
	
	while(!q.empty()){
		P p = q.top();q.pop();
		ll v = p.first.second;
		
		if(v == g) return d[p.second][v];
		
		if(d[p.second][v] < p.first.first) continue;
		
		for(edge e : G[v]){
			if(d[p.second][e.to] > d[p.second][v] + e.cost){
				d[p.second][e.to] = d[p.second][v] + e.cost;
				q.push(P(make_pair(d[p.second][e.to],e.to),p.second));
			}
			if(c > p.second && d[p.second+1][e.to] > d[p.second][v] + e.cost/2){
				d[p.second+1][e.to] = d[p.second][v] + e.cost/2;
				q.push(P(make_pair(d[p.second+1][e.to],e.to),p.second+1));
			}
		}
	}
	
	// int res = INF;
	
	// for(int i = 0; i <= c; i++){
		// res = min(res,d[i][g]);
	// }
	// return res;
}

signed main(){
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int c, n, m, s, d;
	int a, b, f;
	edge temp;
	
	
	while(true){
		vector<edge> G[MAX_VAL];
		
		cin>>c>>n>>m>>s>>d;
		
		if(!c&&!n&&!m&&!s&&!d) break;
		
		for(int i = 0; i < m; i++){
			cin>>a>>b>>f;
			temp.cost = f, temp.to = b;
			G[a].push_back(temp);
			temp.to = a;
			G[b].push_back(temp);
		}
		
		cout<<dijkstra(G,s,d,n,c)<<endl;
	}
	
	return 0;
}