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<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;//cost, v, ticket
struct edge{
  int to, cost;
};

int main(int argc, char *argv[]){
  int c, n, m, s, d;
  while(std::cin >> c >> n >> m >> s >> d, n){
    s--;d--;
    vector<vector<edge> > g(n);
    for (int i = 0; i < m; i++) {
      edge e;
      int from;
      std::cin >> from >> e.to >> e.cost;
      e.to--;from--;
      g[from].push_back(e);
      g[e.to].push_back((edge){from, e.cost});
    }
    vector<vector<int> > dp(c + 1, vector<int>(n, 1e9));
    dp[0][s] = 0;
    priority_queue<piii, vector<piii>, greater<piii> > que;
    que.push(piii(0, pii(s, 0)));
    while(!que.empty()){
      int cost   = que.top().first;
      int v      = que.top().second.first;
      int ticket = que.top().second.second;
      que.pop();
      for (int i = 0; i < g[v].size(); i++) {
        edge e = g[v][i];
        if(dp[ticket][e.to] > dp[ticket][v] + e.cost){
          dp[ticket][e.to] = dp[ticket][v] + e.cost;
          que.push(piii(dp[ticket][e.to], pii(e.to, ticket)));
        }
        if(ticket + 1 <= c &&
           dp[ticket + 1][e.to] > dp[ticket][v] + e.cost/2){
          dp[ticket + 1][e.to] = dp[ticket][v] + e.cost/2;
          que.push(piii(dp[ticket + 1][e.to],
                        pii(e.to, ticket + 1)));
        }
      }
    }
    int ans = 1e9;
    for (int i = 0; i < c; i++) {
      ans = min(ans, dp[i][d]);
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>

using namespace std;

const int inf = 999999;

int func(int dir[101][101], int c, int n, int s, int t)
{
	int r = inf;
	int dp[1<<10+1][101];
	fill(&dp[0][0], &dp[1<<10][100], inf);
	
	dp[(1<<c)-1][s] = 0;
	for(int i = (1<<c)-1; i >= 0; i--){
		r = min(r, dp[i][t]);
		for(int j = 1; j <= n; j++){
			for(int k = 0; k < c; k++){
				if(i >> k & 1){
					for(int l = 1; l <= n; l++){
						if(dp[j][l] >= 0){
							dp[i& ~(1 << k)][l] = min(dp[i & ~(1<<k)][l], (dp[i][j]+dir[j][l]/2));
						}
					}
				}
			}
		}
	}
	
	return r;
}

int main()
{
	int c, n, m, s, d, a, b, f;
	int dir[101][101];
	
	while(cin>>c>>n>>m>>s>>d && c && n && m && s && d){
		fill(&dir[0][0], &dir[100][100], inf);
		for(int i = 0; i <= 100; i++){
			dir[i][i] = 0;
		}
		while(m--){
			cin >> a >> b >> f;
			dir[a][b] = dir[b][a] = f;
		}
		
		cout << func(dir, c, n, s, d) << endl;
	}
	
	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;
}