Go: package main

import (
	"container/heap"
	"fmt"
)

type Node struct {
	NowPosition          int
	DiscountTicketTCount int
	Amount               int
}

type PriorityQueueNode []*Node

func (pq PriorityQueueNode) Len() int {
	return len(pq)
}

func (pq PriorityQueueNode) Less(i, j int) bool {
	return pq[i].Amount < pq[j].Amount
}

func (pq PriorityQueueNode) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueueNode) Push(node interface{}) {
	*pq = append(*pq, node.(*Node))
}

func (pq *PriorityQueueNode) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	*pq = old[0 : n-1]
	return item
}

type Point struct {
	NextPoint int
	Fee       int
}

type Memo struct {
	NowPoint             int
	DiscountTicketTCount int
}

func main() {
	var c, n, m, s, d int
	var a, b, f int

	for {
		fmt.Scan(&c, &n, &m, &s, &d)
		if c == 0 && n == 0 && m == 0 && s == 0 && d == 0 {
			break
		}
		s--
		d--
		pointMap := make([][]Point, n)
		for i := 0; i < n; i++ {
			pointMap[i] = make([]Point, 0, n)
		}
		for i := 0; i < m; i++ {
			fmt.Scan(&a, &b, &f)
			a--
			b--
			pointMap[a] = append(pointMap[a], Point{NextPoint: b, Fee: f})
			pointMap[b] = append(pointMap[b], Point{NextPoint: a, Fee: f})
		}
		pq := make(PriorityQueueNode, 0, m)
		start := Node{NowPosition: s, DiscountTicketTCount: c, Amount: 0}
		heap.Push(&pq, &start)
		memo := make(map[Memo]struct{})
		for len(pq) != 0 {
			now := heap.Pop(&pq).(*Node)
			if now.NowPosition == d {
				fmt.Println(now.Amount)
				break
			}
			memo[Memo{NowPoint: now.NowPosition, DiscountTicketTCount: now.DiscountTicketTCount}] = struct{}{}
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				if _, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok {
					heap.Push(&pq, next)
				}
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					if _, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok {
						heap.Push(&pq, next)
					}
				}
			}
		}
	}
}

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;
}

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;
    }
}