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++: #define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double eps = 1e-8;

int path[101][101];
int used[101][11];

void bfs(int s,int d,int n,int c){
	priority_queue<PP,vector<PP>,greater<PP> > que;
	que.push(PP(0,P(s,c)));
	used[s][c] = 0;

	while(!que.empty()){
		int cost = que.top().first;
		int src = que.top().second.first;
		int ticket = que.top().second.second;
		que.pop();

		for(int dst=1;dst<=n;dst++){
			if(used[dst][ticket] > cost + path[src][dst]){
				used[dst][ticket] = cost + path[src][dst];
				que.push(PP(cost + path[src][dst],P(dst,ticket)));
			}

			if(ticket > 0 && used[dst][ticket-1] > cost + path[src][dst]/2){
				used[dst][ticket-1] = cost + path[src][dst]/2;
				que.push(PP(cost + path[src][dst]/2,P(dst,ticket-1)));
			}
		}
	}
}

int main(){
	//c:number of tickets
	//n:number of towns
	//m:number of buses
	//s:source
	//d:distination
	int c,n,m,s,d;
	while(~scanf("%d %d %d %d %d",&c,&n,&m,&s,&d)){
		if(c==n && n==m && m==s && s==d && d==0) break;
		memset(path,0x3,sizeof(path));
		memset(used,0x3,sizeof(used));

		for(int i=0;i<m;i++){
			int a,b,f;
			scanf("%d %d %d",&a,&b,&f);
			path[a][b] = path[b][a] = min(path[a][b],f);
		}

		bfs(s,d,n,c);
		int res=numeric_limits<int>::max();
		for(int i=c;i>=0;i--) res = min(res,used[d][i]);
		printf("%d\n",res);
	}
}

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

using namespace std;

#define llong long long 
typedef pair<int, llong int> P;

typedef struct data{
	int now;
	llong int time;
	int dep;

	bool operator > (const data& right) const{
		return dep == right.dep ? time > right.time : dep > right.dep;
	}

}data;

int c, n, m, s, d;
vector<P> edges[101];
llong int cost[101][11];
priority_queue<data, vector<data>, greater<data> > q;

void solve(){
	data D;
	D.now = s;
	D.time = 0;
	D.dep = 0;
	q.push(D);

	while(!q.empty()){
		data nd = q.top(); q.pop();
		int nowp = nd.now;
		llong int nowtime = nd.time;
		int nowdep = nd.dep;

		if(cost[nowp][nowdep] < nowtime) continue;

		for(int i = 0; i < edges[nowp].size(); i++){
			P edge = edges[nowp][i];
			if(cost[edge.first][nowdep] > cost[nowp][nowdep] + edge.second){
				data in;
				in.now = edge.first;
				in.time = cost[nowp][nowdep] + edge.second;
				in.dep = nd.dep;
				cost[in.now][in.dep] = in.time;
				q.push(in);
			}

			if(nowdep < c){
				if(cost[edge.first][nowdep + 1] > cost[nowp][nowdep] + edge.second / 2){
					data in;
					in.now = edge.first;
					in.time = nowtime + (edge.second / 2);
					in.dep = nowdep + 1;
					cost[in.now][in.dep] = in.time;
					q.push(in);
				}			
			}

		}
	}

	return;
}

int main(){
	while(cin >> c >> n >> m >> s >> d, n){
		fill_n(*cost, 101 * 11, 99999999);
		for(int i = 0; i <= c; i++){
			cost[s][i] = 0;
		}
		for(int i = 0; i < m; i++){
			int n, to;
			llong int cos;
			cin >> n >> to >> cos;
			edges[n].push_back(P(to, cos));
			edges[to].push_back(P(n, cos));
		}

		solve();

		cout << cost[d][c] << endl;

		for(int i = 0; i < 101; i++){
			edges[i].clear();
		}
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
#include<vector>
#include<queue>
//#include<math.h>
struct crq{
	int cost;
	int ticket;
	int now;

	bool operator >(const crq& p) const{
	return cost > p.cost;
	}
};//cost root que
struct root{
	int s;
	int g;
	int cost;
};

priority_queue<crq,vector<crq>,greater<crq>> q;
vector<root> vr;

int c;
int n;
int m;
int s;
int d;
int ans;
bool townSearched[100];
int townMin[100][11];

int main(){
	while(cin>>c>>n>>m>>s>>d, c|n|m|s|d){
		vr.clear();
		ans=INT_MAX;
		while(!q.empty())q.pop();
		for(int  i=0;i<100;i++){
			townSearched[i]=false;
			for(int  j=0;j<11;j++)townMin[i][j]=INT_MAX;
		}
		for(int i=0;i<m;i++){
			root r;
			cin>>r.s;
			r.s--;
			cin>>r.g;
			r.g--;
			cin>>r.cost;
			vr.push_back(r);
		}
		townMin[s-1][c]=0;
		crq start;
		start.cost=0;
		start.ticket=c;
		start.now=s-1;
		q.push(start);
		while(1){
			crq crq2=q.top();q.pop();
			if(crq2.now==d-1){
				ans=crq2.cost;
				break;
			}
			

			for(int i=0;i<m;i++){
				if(vr.at(i).s==crq2.now){
					if(!townSearched[vr.at(i).g]&&townMin[vr.at(i).g][crq2.ticket]>crq2.cost+vr.at(i).cost){
						crq add;
						add.cost=crq2.cost+vr.at(i).cost;
						add.ticket=crq2.ticket;
						add.now=vr.at(i).g;
						townMin[vr.at(i).g][crq2.ticket]=crq2.cost+vr.at(i).cost;
						q.push(add);
					}

					if(!townSearched[vr.at(i).g]&&crq2.ticket>0&&townMin[vr.at(i).g][crq2.ticket-1]>crq2.cost+vr.at(i).cost/2){
						crq add;
						add.cost=crq2.cost+vr.at(i).cost/2;
						add.ticket=crq2.ticket-1;
						add.now=vr.at(i).g;
						townMin[vr.at(i).g][crq2.ticket]=crq2.cost+vr.at(i).cost/2;
						q.push(add);
					}

				}
				if(vr.at(i).g==crq2.now){
					if(!townSearched[vr.at(i).s]&&townMin[vr.at(i).s][crq2.ticket]>crq2.cost+vr.at(i).cost){
						crq add;
						add.cost=crq2.cost+vr.at(i).cost;
						add.ticket=crq2.ticket;
						add.now=vr.at(i).s;
						townMin[vr.at(i).s][crq2.ticket]=crq2.cost+vr.at(i).cost;
						q.push(add);
					}

					if(!townSearched[vr.at(i).s]&&crq2.ticket>0&&townMin[vr.at(i).s][crq2.ticket-1]>crq2.cost+vr.at(i).cost/2){
						crq add;
						add.cost=crq2.cost+vr.at(i).cost/2;
						add.ticket=crq2.ticket-1;
						add.now=vr.at(i).s;
						townMin[vr.at(i).s][crq2.ticket]=crq2.cost+vr.at(i).cost/2;
						q.push(add);
					}

				}
			}
			townSearched[crq2.now]=true;
		}
		cout<<ans<<endl;
	}
	return 0;
}