Go: package main

import (
	"container/heap"
	"fmt"
	"runtime"
)

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)
					}
				}
			}
		}
		runtime.GC()
	}
}

C++: #include <iostream>

#define MX 1000000000

using namespace std;
int cost[100][100],n;

int dijkstra(int s , int g , int c){
  bool visited[100];
  int d[100][11];
  for(int i=0;i <= c;i++){
    for(int j=0;j < n;j++) d[j][i] = MX , visited[j] = false;
    d[s][i] = 0;
      while(1){
        int u;
        int mincost = MX;
        for(int j=0;j<n;j++)if(!visited[j] && d[j][i] < mincost) mincost = d[j][i],u = j;
        if(mincost == MX) break;
        visited[u] = true;
        for(int v = 0;v < n;v++){
          if(visited[v] || cost[u][v] == MX) continue;
          if(d[v][i] > d[u][i] + cost[u][v]) d[v][i] = d[u][i] + cost[u][v];
          if(i > 0) if(d[v][i] > d[u][i-1] + cost[u][v] / 2) d[v][i] = d[u][i-1] + cost[u][v] / 2;
        }
      }
  }
  return d[g][c];
}

int main(){
  int c,m,s,d;
  while(cin >> c >> n >> m >> s >> d && (c|n|m|s|d)){
    for(int i=0;i<n;i++)for(int j=0;j<n;j++) cost[i][j] = MX;
    while(m--){
      int a,b;
      cin >> a >> b;
      cin >> cost[a-1][b-1];
      cost[b-1][a-1] = cost[a-1][b-1];
    }
    cout << dijkstra(s-1,d-1,c) << endl;
  }
  return 0;
}

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));
                        }
                  }else{
                        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;
      }
}

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