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]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<bits/stdc++.h>
#define MAX_V 101
using namespace std;

struct edge { 
  int to, cost;
  edge(){}
  edge(int to,int cost):to(to),cost(cost){};
};
typedef pair<int ,int> P;
const int INF = 1 << 30;
int V; //ノードの数
vector<edge> Graph[MAX_V];
int min_cost[11][MAX_V];

int c,m,s,d;
void Dijkstra(int s,int chip){ // s:スタートからの最小コストをmin_costに設定
  priority_queue<P,vector< P >, greater<P> > que;
  for(int i=0;i<V;i++) min_cost[chip][i] = INF;
  min_cost[chip][s] = 0;
  que.push(P(0,s));
  
  while(!que.empty()){
    P p = que.top();que.pop();
    int now = p.second;
    int cost = p.first;
    if(min_cost[chip][now] < cost) continue;
    
    for(int i = 0; i < Graph[now].size(); i++){
      edge e = Graph[now][i];
      int a;
      if(chip == 0){
	a = min_cost[chip][now] + e.cost;
      }else{
	a = min(min_cost[chip][now] + e.cost, min_cost[chip-1][now] + e.cost / 2);
	if(min_cost[chip][e.to] > a){
	  min_cost[chip][e.to] = a;
	  que.push(P(min_cost[chip][e.to], e.to));
	}
      }
    }
  }
}

int main(){
  
  while(cin >> c >> V >> m >> s >> d && (c||V||m||s||d)){
    s--;
    d--;
    
    for(int i=0;i<m;i++){
      int a,b,f;
      cin>>a>>b>>f;
      a--;b--;
      Graph[a].push_back(edge(b,f));
      Graph[b].push_back(edge(a,f));
    }
    
    for(int i=0;i<=c;i++){
      Dijkstra(s,i);
    }

    cout<<min_cost[c][d]<<endl;
    
    for(int i=0;i<MAX_V;i++) Graph[i].clear();
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
#include<vector>
#include<queue>
#include<math.h>
struct crq{
	int cost;
	int ticket;
	int now;

	bool operator >(const crq& p) const{
	return cost > p.cost;
	}
};//cost root que
struct root{
	int s;
	int g;
	int cost;
};

priority_queue<crq,vector<crq>,greater<crq>> q;
vector<root> vr;
int c;
int n;
int m;
int s;
int d;
int ans;
bool townSearched[100];
unsigned int townMin[100][11];
int main(){
	while(cin>>c>>n>>m>>s>>d, c|n|m|s|d){
		vr.clear();
		ans=INT_MAX;
		while(!q.empty())q.pop();
		for(int  i=0;i<100;i++){
			townSearched[i]=false;
			for(int  j=0;j<11;j++)townMin[i][j]=INT_MAX;
		}
		for(int i=0;i<m;i++){
			root r;
			cin>>r.s;
			r.s--;
			cin>>r.g;
			r.g--;
			cin>>r.cost;
			vr.push_back(r);
		}
		townMin[s-1][c]=0;
		crq start;
		start.cost=0;
		start.ticket=c;
		start.now=s-1;
		q.push(start);
		while(1){
			crq crq2=q.top();q.pop();
			if(crq2.now==d-1){
				ans=crq2.cost;
				break;
			}
			

			for(int i=0;i<m;i++){
				if(vr.at(i).s==crq2.now){
					if(!townSearched[vr.at(i).g]&&townMin[vr.at(i).g][crq2.ticket]>crq2.cost+vr.at(i).cost){
						crq add;
						add.cost=crq2.cost+vr.at(i).cost;
						add.ticket=crq2.ticket;
						add.now=vr.at(i).g;
						townMin[vr.at(i).g][crq2.ticket]=crq2.cost+vr.at(i).cost;
						q.push(add);
					}

					if(!townSearched[vr.at(i).g]&&crq2.ticket>0&&townMin[vr.at(i).g][crq2.ticket-1]>crq2.cost+vr.at(i).cost/2){
						crq add;
						add.cost=crq2.cost+vr.at(i).cost/2;
						add.ticket=crq2.ticket-1;
						add.now=vr.at(i).g;
						townMin[vr.at(i).g][crq2.ticket]=crq2.cost+vr.at(i).cost/2;
						q.push(add);
					}

				}
				if(vr.at(i).g==crq2.now){
					if(!townSearched[vr.at(i).s]&&townMin[vr.at(i).s][crq2.ticket]>crq2.cost+vr.at(i).cost){
						crq add;
						add.cost=crq2.cost+vr.at(i).cost;
						add.ticket=crq2.ticket;
						add.now=vr.at(i).s;
						townMin[vr.at(i).s][crq2.ticket]=crq2.cost+vr.at(i).cost;
						q.push(add);
					}

					if(!townSearched[vr.at(i).s]&&crq2.ticket>0&&townMin[vr.at(i).s][crq2.ticket-1]>crq2.cost+vr.at(i).cost/2){
						crq add;
						add.cost=crq2.cost+vr.at(i).cost/2;
						add.ticket=crq2.ticket-1;
						add.now=vr.at(i).s;
						townMin[vr.at(i).s][crq2.ticket]=crq2.cost+vr.at(i).cost/2;
						q.push(add);
					}

				}
			}
			townSearched[crq2.now]=true;
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

typedef pair<int,int> pr;
typedef pair<int,pr > ppr;
const int INF=2<<28;
int main() {
	// your code goes here
	int c,n,m,s,d,a,b,f;
	while(cin >> c >> n >> m >> s >> d && c!=0){
		int longs [101][11]={};
		for(int i=1;i<=100;i++)
			for(int j=0;j<=10;j++)
				longs[i][j]=INF;
		priority_queue<ppr,vector<ppr>,greater<ppr> > p;
		vector<pr> root[101];
		for(int i=0;i<m;i++){
			cin >> a>>b >> f;
			root[a].push_back(pr(b,f));
			root[b].push_back(pr(a,f));
		}
		longs[s][0]=0;
		p.push(ppr(0,pr(0,s)));
		while(!p.empty()){
			int f=p.top().first,point=p.top().second.second,t=p.top().second.first;
			p.pop();
			if(longs[point][t]!=f) continue;
			for(int i=0;i<root[point].size();i++){
				int dir=root[point][i].first;
				if(f+root[point][i].second <= longs[dir][t]){
				longs[dir][t]=f+root[point][i].second;
				p.push(ppr(longs[dir][t],pr(t,dir)));
				}
				if(t+1<=c && f+root[point][i].second/2 <= longs[dir][t+1]){
				longs[dir][t+1]=f+root[point][i].second/2;
				p.push(ppr(longs[dir][t+1],pr(t+1,dir)));
				}
			}
		}
		int minim=INF;
		for(int i=0;i<=c;i++)
		minim=min(minim,longs[d][i]);
		cout << minim<< endl;
	}
	return 0;
}