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
}

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)
		}
		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)
		start := Node{NowPosition: s, DiscountTicketTCount: c, Amount: 0}
		heap.Push(&pq, &start)
		for len(pq) != 0 {
			now := heap.Pop(&pq).(*Node)
			if now.NowPosition == d {
				fmt.Println(now.Amount)
				break
			}
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				heap.Push(&pq, next)
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					heap.Push(&pq, next)
				}
			}
		}
	}
}

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