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 <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) string((s).rbegin(), (s).rend())
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

const int INF = 10000;


class V{
public:
	int total;
	int ticket;
	int to;
};
bool operator>(const V &lh, const V &rh){
	return (lh.total > rh.total);
}


int main(){
	while(1){

		int c, n, m, s, d;
		cin >> c >> n >> m >> s >> d;
		if(!(c+n+m+s+d))break;
		n++;
		vector<vector<int> > fare(n, vector<int>(n, INF));
		rep(i, m){
			int a, b, f;
			cin >> a >> b >> f;
			fare[a][b] = fare[b][a] = f;
		}

		vector<vector<int> > best(c+1, vector<int>(n, INF));

		V start;
		start.total = 0;
		start.ticket = 0;
		start.to = s;
		best[0][s] = 0;

		priority_queue<V, vector<V>, greater<V> > q;
		q.push(start);

		while(!q.empty()){
			V p = q.top();
			q.pop();

			if(best[p.ticket][p.to] != p.total) continue;

			rep(i, n){
				if(fare[p.to][i] == INF ) continue;
				V next;
				if(p.total+ fare[p.to][i] < best[p.ticket][i]){
					best[p.ticket][i] = next.total = p.total + fare[p.to][i];
					next.ticket = p.ticket;
					next.to = i;
					q.push(next);
				}
				if(p.ticket < c){
					if(p.total+ fare[p.to][i]/2 < best[p.ticket+1][i]){
						best[p.ticket+1][i] = next.total = p.total + fare[p.to][i]/2;
						next.ticket = p.ticket+1;
						next.to = i;
						q.push(next);
					}
				}
			}
		}

		rep(i, c){
			best[c][d] = min(best[c][d], best[i][d]);
		}

		cout << best[c][d] << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int c,n,m,s,d;
	while(cin>>c>>n>>m>>s>>d,n){
		s--;d--;
		int cost[110][110];
		rep(i,110)rep(j,110)cost[i][j]=inf;
		while(m--){
			int a,b,e;
			cin>>a>>b>>e;
			a--;b--;
			cost[a][b]=cost[b][a]=e;
		}
		int dp[110][11];
		int used[110]={0};
		rep(i,110)rep(j,11)dp[i][j]=inf;
		rep(i,11)dp[s][i]=0;
		while(1){
			int v=-1;
			rep(i,n)if(!used[i]&&(v==-1||dp[v][0]>dp[i][0]))v=i;
			if(v==-1)break;
			used[v]=true;
			rep(i,n)for(int j=c;j>=0;j--){
				dp[i][j]=min(dp[i][j],dp[v][j]+cost[v][i]);
				dp[i][j+1]=min(dp[i][j+1],dp[v][j]+cost[v][i]/2);
			}
		//rep(i,6){rep(j,3)cout<<" "<<dp[i][j];cout<<endl;}
		//cout<<endl;
		}
		//rep(i,6){rep(j,3)cout<<" "<<dp[i][j];cout<<endl;}
		cout<<dp[d][c]<<endl;
	}
}

C++: #include <iostream>
#include <algorithm>
using namespace std;

#define MAX 100
int INF = 1000000;
int G[MAX][MAX];
int c, n, m, s, d, a, b, f;

int dijkstra(){
    int D[MAX][11];
    bool visited[MAX][11];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= c; j++) {
            D[i][j] = INF;
            visited[i][j] = false;
        }
    }
    D[s][c] = 0;
    while (true) {
        int u = 0, w = 0, minv = INF;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= c; j++) {
                if (!visited[i][j] && minv > D[i][j]) {
                    minv = D[i][j];
                    u = i;
                    w = j;
                }
            }
        }
        if (minv == INF) {
            break;
        }
        visited[u][w] = true;
        for (int v = 0; v < n; v++) {
            if (G[u][v] == INF) {
                continue;
            }
            D[v][w] = min(D[v][w], D[u][w] + G[u][v]);
            if (w) {
                D[v][w-1] = min(D[v][w-1], D[u][w] + G[u][v] / 2);
            }
        }
    }
    int minv = INF;
    for (int i = 0; i <= c; i++) {
        minv = min(minv, D[d][i]);
    }
    return minv;
}

int main()
{
    while (true) {
        cin >> c >> n >> m >> s >> d;
        if (s == 0 && d == 0) {
            break;
        }
        s--;
        d--;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                G[i][j] = INF;
            }
        }
        for (int i = 0; i < n; i++) {
            cin >> a >> b >> f;
            a--;
            b--;
            G[a][b] = G[b][a] = f;
        }
        cout << dijkstra() << endl;
    }

    return 0;
}