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 < n; ++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<cstdio>
#include<queue>
#include<algorithm>
#include<vector>
#include<iostream>

using namespace std;

#define PII pair<int,int>
#define PPI pair<int,PII>

#define INF 1000000000

int c;	//øÌ	   1 <= c <=    10
int n;	//¬Ì		   2 <= n <=   100
int m;	//oXÌHü	   1 <= m <=   500
int s,g;//X^[gAS[n_
//int cost[512][512];		//[i][j]Åi©çjÖÌRXg
vector<PII> cost[512];		//firstªto secondªRXg

int d[128][16];

priority_queue< PPI, vector<PPI>, greater<PPI> > Q;
//first ÅZ£ ,second.first ¸_,second.second øðgÁ½


void dijkstra(int s){
	for(int i = 0; i < 128; i++){
		for(int j = 0; j < 16; j++){
			d[i][j] = INF;
		}
	}
	
	d[s][0] = 0;
	
	Q.push(PPI(0,PII(s,0)));
	
	while( !Q.empty() ){
		PPI ppi = Q.top();
		Q.pop();
		int v = ppi.second.first;
		int ca = ppi.second.second;
		
		if( d[v][ca] < ppi.first )continue;
		
		for(int i = 0; i < cost[v].size(); i++){
			PII a = cost[v][i];
			if(d[a.first][ca] > d[v][ca] + a.second ){
				d[a.first][ca] = d[v][ca] + a.second;
				Q.push(PPI(d[a.first][ca],PII(a.first,ca)));
			}
			if(ca < c){
				if(d[a.first][ca+1] > d[v][ca] + a.second/2 ){
					d[a.first][ca+1] = d[v][ca] + a.second/2;
					Q.push(PPI(d[a.first][ca+1],PII(a.first,ca+1)));
				}
			}
		}
	}
}


int main(void){
	
	while(scanf("%d%d%d%d%d", &c, &n, &m, &s, &g) && n != 0){
		int from, to, cos;
		int ans = INF;
		for(int i  =0; i < m; i++){
			scanf("%d%d%d", &from, &to, &cos);
			cost[from].push_back(PII(to,cos));
			cost[to].push_back(PII(from,cos));
		}
		
		dijkstra(s);
		
		for(int i = 0; i <= c; i++){
			ans = min(d[g][i],ans);
		}
		for(int i = 0; i < 512; i++){
			cost[i].clear();
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: // AOJ 0212
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#define rep(i,a) for( int i = 0; i != (a); ++i )

typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;

const int INF = 1 << 30;

int c, n, m, s, d;	
std::vector<P> G[100];
int dist[100][11];

int dijkstra()
{
	std::fill( (int*)dist, (int*)(dist+100), INF );
	dist[s][0] = 0;
	std::priority_queue<PP, std::vector<PP>, std::greater<PP> > pque;
	pque.push( PP( P( s, 0 ), 0 ) );
	while( !pque.empty() )
	{
		PP p = pque.top(); pque.pop();
		int v = p.first.first, cost = p.first.second, tic = p.second;

		if( dist[v][tic] < cost )
			continue;

		rep( i, G[v].size() )
		{
			P &e = G[v][i];

			if( tic < c && dist[e.first][tic+1] > dist[v][tic]+e.second/2 )
			{
				dist[e.first][tic+1] = dist[v][tic]+e.second/2;
				pque.push( PP( P( e.first, dist[e.first][tic+1] ), tic+1 ) );
			}

			if( dist[e.first][tic] > dist[v][tic]+e.second )
			{
				dist[e.first][tic] = dist[v][tic]+e.second;
				pque.push( PP( P( e.first, dist[e.first][tic] ), tic ) );
			}
		}
	}

	return *std::min_element( dist[d], dist[d]+11 );
}

int main()
{
	while( scanf( "%d%d%d%d%d", &c, &n, &m, &s, &d ), c|n|m|s|d )
	{
		--s; --d;
		rep( i, 101 )
			G[i].clear();

		rep( i, m )
		{
			int a, b, f;
			scanf( "%d%d%d", &a, &b, &f );
			--a; --b;
			G[a].push_back( P( b, f ) );
			G[b].push_back( P( a, f ) );
		}

		printf( "%d\n", dijkstra() );
	}

	return 0;
}