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]int)
		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}] = now.Amount
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				if memoAmount, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok || (ok && memoAmount > next.Amount) {
					memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}] = next.Amount
					heap.Push(&pq, next)
				}
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					if memoAmount, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok || (ok && memoAmount > next.Amount) {
						memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}] = next.Amount
						heap.Push(&pq, next)
					}
				}
			}
		}
		//runtime.GC()
	}
}

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

using namespace std;

struct P {
	int from, cost, coupon;

	bool operator >(const P& p) const {
		return cost > p.cost;
	}
};

int ecost[101][101];
int ccost[101][11];
int c, n, m, s, d;
int i;

int main() {
	while(cin >> c >> n >> m >> s >> d, c|n|m|s|d) {
		fill_n((int *)ecost, 101*101, -1);
		fill_n((int *)ccost, 101*11, 1e8);
		for(i=0; i<11; i++) ccost[s][i] = 0;
		for(i=0; i<m; i++){
			int a, b, f;
			cin >> a >> b >> f;
			ecost[a][b] = f;
			ecost[b][a] = f;
		}
		priority_queue<P, vector<P>, greater<P>> q;
		q.push((P){s, 0, 0});
		int dcost;
		while(!q.empty()){
			P p = q.top(); q.pop();
			// cout << "pos=" << p.from << endl;
			// goal
			if(p.from == d) {
				dcost = p.cost;
				break;
			}
			//
			for(i=0; i<n+1; i++){ // i:to
				if(ecost[p.from][i] != -1){
					bool ifpush = true;
					for(int j=0; j <= p.coupon; j++) ifpush = ifpush && p.cost + ecost[p.from][i] < ccost[i][j];
					if(ifpush) {
					//if(p.cost + ecost[p.from][i] < ccost[i][p.coupon]){
						q.push((P){i, p.cost + ecost[p.from][i], p.coupon});
					}
					if(p.coupon+1 <= c) {
						bool ifpush = true;
						for(int j=0; j <= p.coupon+1; j++) ifpush = ifpush && p.cost + ecost[p.from][i]/2 < ccost[i][j];
						if(ifpush) {
						// if(p.cost + ecost[p.from][i]/2 < ccost[i][p.coupon+1]){
							q.push((P){i, p.cost + ecost[p.from][i]/2, p.coupon+1});
						}
					}
				}
			}
		}
		cout << dcost << endl;
	}
	return 0;
}

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

using namespace std;

struct node {
	int to, cost, ticket;

	node(int to, int cost) : to(to), cost(cost) { this -> ticket = 0; }
	node(int to, int cost, int ticket) : to(to), cost(cost), ticket(ticket) { }
	node() { this -> to = this -> cost = this -> ticket = 0; }
};

bool operator < (const node &a, const node &b) {
	return a.cost < b.cost;
}

bool operator > (const node &a, const node &b) {
	return a.cost > b.cost;
}

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

		vector< vector<node> > v(n);
		for (int i = 0; i < m; ++i) {
			int a, b, f; cin >> a >> b >> f;
			--a, --b;
			v[a].push_back( node(b, f) );
			v[b].push_back( node(a, f) );
		}

		vector< vector<int> > cost(n, vector<int>(c+1, -1));
		vector<bool> used(n, -1);
		priority_queue< node, vector<node>, greater<node> > que; que.push( node(s, 0, c) );
		while ( !que.empty() ) {
			node next = que.top(); que.pop();

			if (cost[next.to][next.ticket] >= 0) continue;

			cost[next.to][next.ticket] = next.cost;

			for (int i = 0; i < v[next.to].size(); ++i) {
				que.push( node(v[next.to][i].to, next.cost + v[next.to][i].cost, next.ticket) );
				if (next.ticket) que.push( node(v[next.to][i].to, next.cost + v[next.to][i].cost/2, next.ticket-1) );
			}
		}

		cout << cost[d][0] << endl;
	}
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
double EPS=1e-10;
int INF=1e9;
static const int MEM_SIZE=1000000;
struct edge{int to,cost;};
struct dat{
      int s,cost,num;
      dat(int s,int cost,int num):s(s),cost(cost),num(num){}
      bool operator<(const dat& a)const{return cost<a.cost;}
};
vector<edge> G[100];
int dist[100][11];
int n,c;
void dijkstra(int s){
      REP(i,100)REP(j,11)dist[i][j]=INF;
      priority_queue<dat>Q;
      Q.push(dat(s,0,0));
      dist[s][0]=0;
      while(!Q.empty()){
            dat p=Q.top();Q.pop();
            if(p.cost>dist[p.s][p.num])continue;
            REP(i,G[p.s].size()){
                  edge e=G[p.s][i];
                  if(p.num<c){
                        if(dist[p.s][p.num]+e.cost/2<dist[e.to][p.num+1]){
                              dist[e.to][p.num+1]=dist[p.s][p.num]+e.cost/2;
                              Q.push(dat(e.to,dist[e.to][p.num+1],p.num+1));
                        }
                  }
                  if(dist[p.s][p.num]+e.cost<dist[e.to][p.num]){
                        dist[e.to][p.num]=dist[p.s][p.num]+e.cost;
                        Q.push(dat(e.to,dist[e.to][p.num],p.num));
                  }
            }
      }
}
int main(){
      int m,s,d;
      while(cin>>c>>n>>m>>s>>d&&(c||n||m||s||d)){
            s--;d--;
            REP(i,100)G[i].clear();
            REP(i,m){
                  int a,b,f;
                  cin>>a>>b>>f;
                  a--;b--;
                  G[a].PB((edge){b,f});
                  G[b].PB((edge){a,f});
            }
            dijkstra(s);
            int ans=INF;
            /*REP(i,n){
                  REP(j,c+1){
                        cout<<dist[i][j];
                        if(j==c-1)cout<<endl;
                        else cout<<" ";
                        //cout<<i<<" "<<j<<endl;
                  }
            }*/
            REP(i,c+1)ans=min(ans,dist[d][i]);
            cout<<ans<<endl;
      }
}