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<map>
#define MAX 10000000
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
struct edge{
	int cost,to;
};
typedef pair<int,int> p;
typedef pair<int,p> P;
//`Pbg@»ÝÌ@v
int main(){
	int tic,n,m,s,a,b,g,d[11][101],f;
	//d ticket place
	while(cin>>tic>>n>>m>>s>>g,tic||n||m||s||g){
		s--;g--;
		//tic `Pbg
		//n Ì
		//m ´Ì
		//s¨g
		vector<edge> v[101];
		rep(i,m){
			cin>>a>>b>>f;
			a--;b--;
			edge c;
			c.cost=f;
			c.to=b;v[a].push_back(c);
			c.to=a;v[b].push_back(c);
		}
		rep(i,tic+1)
		rep(j,n){
			if(j==s)
			d[i][j]=0;
			else
			d[i][j]=MAX;
		}
		int nowticket,nowplace,nowsum;
		priority_queue<P,vector<P>,greater<P> > que;
		P now;
		que.push(P(tic,p(s,0)));
		while(!que.empty()){
			now=que.top();
			que.pop();
			nowticket=now.first;
			nowplace=now.second.first;
			nowsum=now.second.second;
			if(d[nowticket][nowplace]<nowsum)
				continue;
			rep(i,(int)v[nowplace].size()){
				edge e=v[nowplace][i];
				if(nowticket>0){
					if(d[nowticket-1][e.to]>e.cost/2+nowsum){
						d[nowticket-1][e.to]=e.cost/2+nowsum;
						que.push(P(nowticket-1,p(e.to,d[nowticket-1][e.to])));
					}
				}
				if(d[nowticket][e.to]>e.cost+nowsum){
						d[nowticket][e.to]=e.cost+nowsum;
						que.push(P(nowticket,p(e.to,d[nowticket][e.to])));
				}
			}
		}
		int mi=100000000;
		rep(i,tic+1)
		mi=min(mi,d[i][g]);
		cout<<mi<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

#define MAX_N 101
#define MAX_C 11

#define WHITE 0
#define GRAY 1
#define BLACK 2

typedef pair<int, int> pii;

struct edge { int to, c; };

vector<edge> G[MAX_N];
int color[MAX_N];
int	minc[MAX_C][MAX_N]; //dp?????????????????° ????????????id

void dijkstra(int C, int s) {
	priority_queue<pii, vector<pii>, greater<pii> >PQ; //minc v

	memset(color, WHITE, sizeof(color));
	fill(minc[C], minc[C + 1], INF);

	//?§????
	PQ.push(pii(0, s));
	minc[C][s] = 0;
	color[s] = GRAY;

	//PQ???????´????????????°
	while (!PQ.empty()) {
		//minc???????°??????¨??????????´????????????????
		pii p = PQ.top(); PQ.pop();

		int u = p.second;
		color[u] = BLACK;
		//????????§???????????°??????
		if (minc[C][u] < p.first) continue;

		//??£??\????????????????????¨????????????
		for (int j = 0; j < G[u].size(); j++) {
			edge e = G[u][j];
			if (color[e.to] == BLACK)continue;
			int m = (C == 0 ? minc[C][u] + e.c : min(minc[C][u] + e.c, minc[C - 1][u] + e.c / 2));
			if (minc[C][e.to] > m) {
				minc[C][e.to] = m;
				PQ.push(pii(minc[C][e.to], e.to));
				color[e.to] = GRAY;
			}
		}
	}
}

int main() {
	for (int C, n, m, s, d; cin >> C >> n >> m >> s >> d&&C;) {
		for (int i = 0; i < m; i++) {
			int a, b, f; scanf("%d%d%d", &a, &b, &f);
			edge e; e.to = b; e.c = f;
			G[a].push_back(e);
			e.to = a; e.c = f;
			G[b].push_back(e);
		}
		for (int i = 0; i <= C; i++) {
			dijkstra(i, s);
		}

		cout << minc[C][d] << endl;

		for (int i = 0; i <= n; i++) {
			G[i].clear();
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < k; i++)
typedef long long ll;
typedef unsigned long long ull;

struct edge{
	int to,cost,dis;
};

bool operator < (const edge &a,const edge &b){
    return a.cost > b.cost;
}

int main(){
	int c,n,m,s,g;
	while(scanf("%d%d%d%d%d",&c,&n,&m,&s,&g),n){
		int ans = 0;
		s--,g--;
		vector<edge> G[128];
		int d[128][32]={{}};
		rep(i,m){
			int a,b,cst;
			scanf("%d%d%d",&a,&b,&cst);
			a--,b--;
			edge in;
			in = {b,cst,-1};
			G[a].push_back(in);
			in = {a,cst,-1};
			G[b].push_back(in);
		}
		priority_queue<edge> PQ;
		edge start = {s,0,c};
		PQ.push(start);
		while(!PQ.empty()){
			edge pq = PQ.top();
			PQ.pop();
			if(d[pq.to][pq.dis]){
				d[pq.to][pq.dis]++;
				continue;
			}
			d[pq.to][pq.dis] = true;
			if(pq.to == g){
				printf("%d\n",pq.cost);
				break;
			}
			rep(u,G[pq.to].size()){
				edge next = {G[pq.to][u].to,pq.cost+G[pq.to][u].cost,pq.dis};
				PQ.push(next);
				if(pq.dis){
					next = {G[pq.to][u].to,pq.cost+G[pq.to][u].cost/2,pq.dis-1};
					PQ.push(next);
				}
			}
		}
	}
	return 0;
}