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 <iostream>
#include <algorithm>
#include <queue>
using namespace std;

#define INF ((int)1e9)

struct Edge {
  int to, cost;
  Edge(int t, int c) : to(t), cost(c) {}
};

typedef pair<int, int> Pii;
typedef pair<int, Pii> Piii; // cost, cnum, node

vector<Edge> G[100];
int memo[100][10];

int dijkstra(int src, int dst, int cnum) {
  
  fill(memo[0], memo[0]+1000, INF);
  
  priority_queue<Piii> pq;
  memo[src][cnum] = 0;
  pq.push(Piii(0, Pii(cnum, src)));
  while(!pq.empty()) {
    const Piii get = pq.top(); pq.pop();
    int cost = get.first;
    int cn = get.second.first;
    int now = get.second.second;
    
    for(int i=0; i<G[now].size(); i++) {
      int next = G[now][i].to;
      int add_c = G[now][i].cost;
      if(memo[next][cn] > cost + add_c) {
	pq.push(Piii(cost+add_c, Pii(cn, next)));
	memo[next][cn] = cost + add_c;
      }
      if(cn-1<0) continue;
      add_c /= 2;
      if(memo[next][cn-1] > cost + add_c) {
	pq.push(Piii(cost+add_c, Pii(cn, next)));
	memo[next][cn-1] = cost + add_c;
      }
    }
  }
  
  return *min_element(memo[dst], memo[dst]+10);
}

int main() {
  int C, N, M, S, D;
  while(cin >> C >> N >> M >> S >> D && (N|M)) {
    for(int i=0; i<N; i++) {
      G[i].clear();
    }
    for(int i=0; i<M; i++) {
      int a, b, c; cin >> a >> b >> c; a--, b--;
      G[a].push_back(Edge(b, c));
      G[b].push_back(Edge(a, c));
    }
    
    S --, D --;
    cout << dijkstra(S, D, C) << endl;
  }
  
  return 0;
}

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]){
						ccost[i][p.coupon] = p.cost + ecost[p.from][i];
						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]){
							ccost[i][p.coupon+1] = p.cost + ecost[p.from][i]/2;
							q.push((P){i, p.cost + ecost[p.from][i]/2, p.coupon+1});
						}
					}
				}
			}
		}
		cout << dcost << endl;
	}
	return 0;
}

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]; // 0:not use coupon 1:use coupon
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<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();
			// goal
			if(p.from == d) {
				dcost = p.cost;
				break;
				P p2 = q.top();
				while(p.cost <= p2.cost && p.coupon <= p2.coupon){
					q.pop();
				}
				if(q.empty()) break;
				else continue;
			}
			//
			for(i=0; i<n+1; i++){ // i:to
				if(ecost[p.from][i] != -1){
					q.push((P){i, p.cost + ecost[p.from][i], p.coupon});
					if(p.coupon+1 <= c) {
						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});
						}
					}
					ecost[p.from][i] = -1;
					ecost[i][p.from] = -1;
				}
			}
		}
		cout << dcost << endl;
	}
	return 0;
}