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<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge{int to,from,cost;};

#ifdef DEBUGLOCAL
#define debug cout
#else
stringstream __ss__;
#define debug __ss__
#endif

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) debug << *i << " "; debug << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;i--)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);i--)
#define rep0(i,n) for(i=0;i<(n);++i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[]={1,-1,0,0,1,-1,1,-1,0};
const int dy[]={0,0,1,-1,1,-1,-1,1,0};

int c,n,m,s,d;
int edge[1111][1111];
int cost[111][1111];

int main() {
	IL{
		cin>>c>>n>>m>>s>>d;
		--s,--d;
		if(c==0)break;
		int fr,to,co;
		rep(i,111)rep(j,111)edge[i][j]=INF;
		rep(i,m){
			cin>>fr>>to>>co;
			--fr,--to;
			chmin(edge[fr][to],co);
			chmin(edge[to][fr],co);
		}
		rep(i,11)rep(j,111)cost[i][j]=INF;
		priority_queue<pair<int,pint>,vector<pair<int,pint> >,greater<pair<int,pint> > > que;
		que.push(MP(0,MP(0,s)));
		while(!que.empty()){
			pair<int,pint> p;
			p=que.top();
			que.pop();
			if(p.second.first>c)continue;
			if(cost[p.second.first][p.second.second]<=p.first)continue;
			cost[p.second.first][p.second.second]=p.first;
			rep(i,n){
				if(edge[p.second.second][i]==INF)continue;
				pair<int,pint> next=p;
				next.first+=edge[p.second.second][i]/2;
				++next.second.first;
				next.second.second=i;
				que.push(next);
				next.first+=edge[p.second.second][i]/2;
				--next.second.first;
				que.push(next);
			}
		}
		int res=INF;
		repn(i,0,n){
			chmin(res,cost[i][d]);
		}
		cout<<res<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
struct Edge{
    Edge(){};
    Edge(int _to,int _cost){
        to = _to;
        cost = _cost;
    }
    int to;
    int cost;
};
struct Data{
    Data(){};
    Data(int _pos,int _t, int _ck){
        pos = _pos;
        t = _t;
        ck = _ck;
    }
    int pos;
    int t;
    int ck;
    bool operator < (const Data &a)const{
        return t > a.t;
    }
};
int main(){
    int c,n,m,s,d;
    while(cin>>c>>n>>m>>s>>d,c){
        int vis[120][12];
        vector<Edge> Node[120];
        for(int i = 0;i < m;i++){
            int x,y,t;
            cin>>x>>y>>t;
            Node[x].push_back(Edge(y,t));
            Node[y].push_back(Edge(x,t));
        }
        for(int i = 0;i < 120;i++)for(int j = 0;j < 12;j++)vis[i][j] = 1e+9;
        priority_queue<Data> Q;
        Q.push(Data(s,0,0));
        while(!Q.empty()){
            Data D = Q.top();Q.pop();
            int p = D.pos;
            int k = D.ck;
            if(vis[p][k] < D.t)continue;
            for(int i = 0;i < Node[p].size();i++){
                Edge e = Node[p][i];
                if(vis[e.to][k] > D.t + e.cost){
                    vis[e.to][k] = D.t + e.cost;
                    Q.push(Data(e.to,vis[e.to][k],k));
                }
                if(k < c && vis[e.to][k + 1] > D.t + e.cost/2){
                    vis[e.to][k + 1] = D.t + e.cost/2;
                    Q.push(Data(e.to,vis[e.to][k + 1],k+1));
                }
            }
        }

        int ans = 1e+9;
        for(int i = 0;i <= c;i++){
            ans = min(ans, vis[d][i]);
        }
        cout<<ans<<endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

typedef pair<int, pair<int, int>> STATE;

const int INF = INT_MAX / 4;

int main(void) {
	int c, n, m, s, d;

	while (cin >> c >> n >> m >> s >> d, c) {
		s--; d--;

		VVI es(n, VI(n, INF));
		for (int i = 0; i < m; i++) {
			int a, b, f;
			cin >> a >> b >> f;
			es[a - 1][b - 1] = f;
			es[b - 1][a - 1] = f;
		}

		VVI distance(n, VI(c + 1, INF));	// node, ticket
		distance[s][c] = 0;
		priority_queue<STATE, vector<STATE>, greater<STATE>> q; // cost, node, ticket
		q.push(STATE(0, make_pair(s, c)));

		while (q.size()) {
			int cost = q.top().first;
			int node = q.top().second.first;
			int ticket = q.top().second.second;
			q.pop();

			if (cost > distance[node][ticket]) {
				continue;
			}

			for (int i = 0; i < n; i++) if (es[node][i] != INF) {
				int next_cost;

				// not use ticket
				next_cost = distance[node][ticket] + es[node][i];
				if (distance[i][ticket] > next_cost) {
					distance[i][ticket] = next_cost;
					q.push(STATE(next_cost, make_pair(i, ticket)));
				}

				// ticket - 1
				if (ticket) {
					next_cost = distance[node][ticket] + es[node][i] / 2;
					if (distance[i][ticket - 1] > next_cost) {
						distance[i][ticket - 1] = next_cost;
						q.push(STATE(next_cost, make_pair(i, ticket - 1)));
					}
				}
			}
		}

		cout << *min_element(distance[d].begin(), distance[d].end()) << endl;
	}

	return 0;
}