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 "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

int c,n,m;
int pass[200][200];

double d[200][20];
bool used[200][20];

int dijk(int s,int g){
    rep(i,200)rep(j,20){
        d[i][j]=INF;
        used[i][j]=false;
    }
    
    d[s][c]=0;
    
    while(1){
        int v=-1;
        int w=-1;
        rep(u,n){
            rep(i,c+1){
                if( !used[u][i] && (v==-1||d[u][i]<d[v][w]) )v=u,w=i;
            }
        }
        if(v==-1)break;
        
        used[v][w]=true;
        
        rep(u,n){
            d[u][w] = min(d[u][w] , d[v][w] + pass[v][u] );
//            cout<<"d["<<u<<"]["<<w<<"]="<<d[u][w]<<endl;
            if(w-1>=0 && pass[v][u]!=INF){
                d[u][w-1] = min(d[u][w-1] , d[v][w] + (pass[v][u]/2.0) );
//                cout<<"d["<<u<<"]["<<w-1<<"]="<<d[u][w-1]<<endl;
            }
        }
    }
    double ret=INF;
    rep(i,c+1){
        ret = min(ret,d[g][i]);
    }
    return ret;
}


int main(){
    int s,g;
    while(cin>>c>>n>>m>>s>>g){
        if(c==0&&n==0&&m==0&&s==0&&g==0)break;
        
        s--,g--;
        rep(i,200)rep(j,200)pass[i][j]=INF;
        rep(i,200)pass[i][i]=0;
        
        rep(i,m){
            int a,b,f;
            cin>>a>>b>>f;
            a--,b--;
            pass[a][b]=pass[b][a]=f;
        }
        
    cout<<dijk(s,g)<<endl;
    }
}

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

#define loop(i, n) for (int i = 0; i < n; i++)
#define INF 1010001000

typedef pair<int, int> i_i;
typedef struct data{int pos, tick, cost;}data;

int dp(vector<vector<i_i > > &g);

int c, n, m, s, d;

int main(void)
{
    while (cin >> c >> n >> m >> s >> d, c) {
        n++;
        vector<vector<i_i > > g(n);
        loop(i, m) {
            int a, b, f;
            cin >> a >> b >> f;
            g[a].push_back(i_i(f, b));
            g[b].push_back(i_i(f, a));
        }
        cout << dp(g) << endl;
    }
    return 0;
}

int dp(vector<vector<i_i > > &g)
{
    vector<vector<int> > table(c+1, vector<int>(n, INF));
    queue<data> a;
    data dt = {s, c, 0};
    a.push(dt);
    while (!a.empty()) {
        data tmp = a.front(); a.pop();
        for (i_i i : g[tmp.pos]) {
            if (table[tmp.tick][i.second] > tmp.cost + i.first) {
                table[tmp.tick][i.second] = tmp.cost + i.first;
                dt.pos = i.second; dt.tick = tmp.tick; 
                dt.cost = tmp.cost + i.first;
                a.push(dt);
            }
            if (tmp.tick && 
                    table[tmp.tick-1][i.second] > tmp.cost + i.first) {
                table[tmp.tick-1][i.second] = tmp.cost + i.first / 2;
                dt.pos = i.second; dt.tick = tmp.tick-1; 
                dt.cost = tmp.cost + i.first / 2;
                a.push(dt);
            }
        }
    }
    int ret = INF;
    for (int i = 0; i < c+1; i++) {
        ret = min(ret, table[i][d]);
    }
    return ret;
}

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

using namespace std;

#define INF 100000000

struct edge {
	int to, cost;
};

int main() {
	int c, n, m, s, d;
	while (cin >> c >> n >> m >> s >> d) {
		if (c == 0 && n == 0 && m == 0 && s == 0 && d == 0) {
			break;
		}
		vector<edge> ff[101];
		vector< vector<int> > ddd(n+1, vector<int>(n+1, INF));
		int a, b, f;
		for (int i = 0; i < m; i++) {
			cin >> a >> b >> f;
			edge e;
			e.to = b;
			e.cost = f;
			ff[a].push_back(e);
			e.to = a;
			ff[b].push_back(e);
			ddd[a][b] = ddd[b][a] = f;
		}
		for (int i = 1; i <= n; i++) {
			ddd[i][i] = 0;
		}
		for (int k = 1; k <= n; k++) {
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					ddd[i][j] = min(ddd[i][j], ddd[i][k]+ddd[k][j]);
				}
			}
		}
		vector<int> isd[101];
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (ddd[i][j] != INF) {
					isd[i].push_back(j);
				}
			}
		}
		vector< vector< vector<int> > > dp(n+1, vector< vector<int> >(n+1, vector<int>(c+1, INF)));
		for (int i = 1; i <= n; i++) {
			dp[s][i][0] = ddd[s][i];
		}
		for (int k = 1; k <= c; k++) {
			for (int p = 0; p < isd[s].size(); p++) {
				int pp = isd[s][p];
				dp[s][pp][k] = dp[s][pp][k-1];
				for (int i = 0; i < isd[s].size(); i++) {
					int ii = isd[s][i];
					for (int j = 0; j < isd[ii].size(); j++) {
						int jj = isd[ii][j];
						for (int q = 0; q < ff[jj].size(); q++) {
							int qq = ff[jj][q].to;
							if (ddd[qq][pp] == INF) continue;
							if (dp[s][pp][k] > dp[s][ii][k-1]+ddd[ii][jj]+(ff[jj][q].cost/2)+ddd[qq][pp]) {
								dp[s][pp][k] = dp[s][ii][k-1]+ddd[ii][jj]+(ff[jj][q].cost/2)+ddd[qq][pp];
							}
						}
					}
				}
			}
		}
		cout << dp[s][d][c] << endl;
	}
	return 0;
}