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 <algorithm>
#include <vector>
#define INF 10e6 
using namespace std;

int c,n,m,s,d;

int cost[101][101];
bool state[101][11];
struct node{
	int c;  //cost
	int n;	//number
	int t;	//times
	bool operator >(node b)const{
    return c > b.c;
	}
};




int dijkstra(int s,int g){
	node start;
	start.c=0,start.n=s,start.t=c;
	priority_queue<node,vector<node>,greater<node> > q;
	q.push(start);
	while(!q.empty()){
		node cur=q.top();
		q.pop();
		if(cur.n == g){
			int ans=cur.c;
			return ans;
		}
		if(state[cur.n][cur.t])
			continue;
		else
			state[cur.n][cur.t]=true;; 
		for(int i=1;i<=n;i++){
			if(cur.n== i)
				continue;
			node next;
			if(cur.t > 0){
				next.c=cur.c+(cost[cur.n][i]/2);
				next.n=i;
				next.t=cur.t-1;
				q.push(next);
			}
			next.c=cur.c+cost[cur.n][i];
			next.n=i;
			next.t=cur.t;
			q.push(next);
		}
	} 
	return INF;
}
int main(void){
	while(cin >> c >> n >> m >> s >> d,c|n|m|s|d){
		for(int i=1;i<=n;i++)
			for(int j=1;j<=c;j++)
				state[i][j]=false;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				cost[i][j]=INF;
		int a,b,f;
		for(int i=0;i<m;i++){
			cin >> a >> b >> f;
			cost[a][b]=cost[b][a]=f;
		}
		int ans=dijkstra(s,d);
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#define INF 10e6 
using namespace std;

int c,n,m,s,d;

int cost[101][101];

struct node{
	int c;  //cost
	int n;	//number
	int t;	//times
	bool operator >(node b)const{
    return c > b.c;
	}
};




int dijkstra(int s,int g){
	node start;
	start.c=0,start.n=s,start.t=c;
	priority_queue<node,vector<node>,greater<node> > q;
	q.push(start);
	while(!q.empty()){
		node cur=q.top();
		q.pop();
		if(cur.n == g){
			int ans=cur.c;
			return ans;
		}
		for(int i=1;i<=n;i++){
			if(cur.n== i)
				continue;
			node next;
			if(cur.t > 0){
				next.c=cur.c+(cost[cur.n][i]/2);
				next.n=i;
				next.t=cur.t-1;
				q.push(next);
			}
			next.c=cur.c+cost[cur.n][i];
			next.n=i;
			next.t=cur.t;
			q.push(next);
		}
	} 
	return INF;
}
int main(void){
	while(cin >> c >> n >> m >> s >> d,c|n|m|s|d){
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				cost[i][j]=INF;
		int a,b,f;
		for(int i=0;i<m;i++){
			cin >> a >> b >> f;
			cost[a][b]=cost[b][a]=f;
		}
		int ans=dijkstra(s,d);
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <queue>

#define INF 1e9

using namespace std;

struct Edge {
	int to, cost;
};
struct Node {
	int now, rest, cost;
};
bool operator <(const Node& n1, const Node& n2) {
	return n1.cost < n2.cost;
}

int main() {
	int c, n, l, s, d;
	while ( cin >> c >> n >> l >> s >> d, c || n || l || s || d ) {
		--s, --d;

		vector<Edge> m[100];
		for (int i = 0; i < l; ++i) {
			int a, b, f; cin >> a >> b >> f; --a, --b;
			m[a].push_back( (Edge){ b, f } );
			m[b].push_back( (Edge){ a, f } );
		}

		int ans[100][11]; fill(&ans[0][0], &ans[0][0]+100*11, INF);
		priority_queue<Node> Q; Q.push( (Node){s, c, 0} );
		while ( !Q.empty() ) {
			Node node = Q.top(); Q.pop();
			if (node.cost >= ans[node.now][node.rest]) continue;
			ans[node.now][node.rest] = node.cost;

			for (int i = 0; i < m[node.now].size(); ++i) {
				Edge& e = m[node.now][i];
				if (node.cost+e.cost < ans[e.to][node.rest]) {
					Q.push( (Node){ e.to, node.rest, node.cost+e.cost } );
				}

				if (node.rest > 0) {
					if (node.cost+e.cost/2 < ans[e.to][node.rest-1]) {
						Q.push( (Node){ e.to, node.rest-1, node.cost+e.cost/2 } );
					}
				}
			}
		}
		int a = INF;
		for (int i = 0; i <= c; ++i) a = min(a, ans[d][i]);
		cout << a << endl;
	}
}

C++: #include <iostream>
#include <queue>
#include <functional>
#include <algorithm>

const int MAX_V = 100;
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();
	}
}