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 long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

struct edge{int to,cost;};
vector<edge> G[100];

const int INF=123456789;
int dist[11][100];

int main()
{
    int c,n,m,s,d;
    while(cin >>c >>n >>m >>s >>d,c)
    {
        rep(i,100) G[i].clear();

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

        fill(dist[0],dist[11],INF);
        dist[0][s]=0;
        queue<pi> que;
        que.push(pi(0,s));
        while(!que.empty())
        {
            pi p=que.front(); que.pop();
            int ticket=p.fi;
            int now=p.se;
            rep(i,G[now].size())
            {
                edge e=G[now][i];
                if(dist[ticket][e.to]>dist[ticket][now]+e.cost)
                {
                    dist[ticket][e.to]=dist[ticket][now]+e.cost;
                    que.push(pi(ticket,e.to));
                }
                if(ticket<c)
                {
                    if(dist[ticket+1][e.to]>dist[ticket][now]+e.cost/2)
                    {
                        dist[ticket+1][e.to]=dist[ticket][now]+e.cost/2;
                        que.push(pi(ticket+1,e.to));
                    }
                }
            }
        }

        int ans=INF;
        rep(i,c+1) ans=min(ans,dist[i][d]);
        printf("%d\n", ans);
    }
    return 0;
}

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

class edge{
	public:
		int to,cost;
		edge();
		edge(int _to,int _cost){
			to = _to;
			cost = _cost;
		}
};
class state{
	public:
		int id,cost,ticket;
		state();
		state(int _id,int _cost,int _ticket){
			id = _id;
			cost = _cost;
			ticket = _ticket;
		}
		bool operator<(const state st)const{
			return cost > st.cost;
		}
};
const int INF = 1000000;

int main()
{
	int c,n,m,s,g;
	while(cin >> c >> n >> m >> s >> g){
		if(!c&&!n&&!m&&!s&&!g)
			break;
		vector<edge> t[100];
		int d[100][11];
		for(int i=0;i<m;i++){
			int a,b,cost;
			cin >> a >> b >> cost;
			a--;b--;
			t[a].push_back(edge(b,cost));
			t[b].push_back(edge(a,cost));
		}
		s--;g--;

		int ans = INF;
		for(int i=0;i<11;i++){
			fill(d[i],d[i]+100,INF);
		}
		d[s][c] = 0;
		priority_queue<state> que;
		que.push(state(s,0,c));
		while(!que.empty()){
			state st = que.top();
			que.pop();
			int v = st.id;
			if(st.id == g)
				ans = min(ans,st.cost);
			for(unsigned i=0;i<t[v].size();i++){
				edge e = t[v][i];
				
				if(d[e.to][st.ticket] > d[v][st.ticket] + e.cost){
					d[e.to][st.ticket] = d[v][st.ticket] + e.cost;
					que.push(state(e.to,d[e.to][st.ticket],st.ticket));
				}
				if(st.ticket>0){
					if(d[e.to][st.ticket-1] > d[v][st.ticket] + (e.cost)/2){
						d[e.to][st.ticket-1] = d[v][st.ticket] + (e.cost)/2;
						que.push(state(e.to,d[e.to][st.ticket-1],st.ticket-1));
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
struct Edge{
    int to,cost;
};
struct data{
    int nowp,sumcost,tic;
    data(){}
    data(int _nowp,int _sumcost,int _tic){
        nowp=_nowp,sumcost=_sumcost,tic=_tic;
    }
    bool operator<(const data &a)const{
        return sumcost>a.sumcost;
    }
};
const int INF=100000000;
int main(){
    while(1){
        int c,n,m,s,g;
        vector<Edge> edge[102];
        scanf("%d %d %d %d %d",&c,&n,&m,&s,&g);
        if(c==0&&n==0&&m==0&&s==0&&g==0)
            break;
        for(int i=0;i<m;i++){
            int be,af,co;
            scanf("%d %d %d",&be,&af,&co);
            Edge a;
            a.to=af,a.cost=co;
            edge[be].push_back(a);
            a.to=be;
            edge[af].push_back(a);
        }
        int coslis[11][102];
        fill(coslis[0],coslis[0]+11*102,INF);
        priority_queue<data> que;
        que.push(data(s,0,c));
        while(!que.empty()){
            data nowrig=que.top(); que.pop();
            //printf(" %d,%d,%d\n",nowrig.nowp,nowrig.sumcost,nowrig.tic);
            if(coslis[nowrig.tic][nowrig.nowp]!=INF)
                continue;
            coslis[nowrig.tic][nowrig.nowp]=nowrig.sumcost;
            for(int i=0;i<edge[nowrig.nowp].size();i++){
                data a;
                a.nowp=edge[nowrig.nowp][i].to;
                a.sumcost=nowrig.sumcost+edge[nowrig.nowp][i].cost;
                a.tic=nowrig.tic;
                que.push(a);
                if(0<nowrig.tic){
                    a.sumcost=nowrig.sumcost+(edge[nowrig.nowp][i].cost/2);
                    a.tic=nowrig.tic-1;
                    que.push(a);
                }
            }
        }
        int ans=INF;
        for(int i=0;i<=10;i++)
            ans=min(ans,coslis[i][g]);
        printf("%d\n",ans);
    }
    return 0;
}