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
}

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)
		}
		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)
		start := Node{NowPosition: s, DiscountTicketTCount: c, Amount: 0}
		heap.Push(&pq, &start)
		for len(pq) != 0 {
			now := heap.Pop(&pq).(*Node)
			if now.NowPosition == d {
				fmt.Println(now.Amount)
				break
			}
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				heap.Push(&pq, next)
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					heap.Push(&pq, next)
				}
			}
		}
	}
}

C++: #include <iostream>
#include <queue>
//#include <fstream>	// require freopen

using namespace std;

const int MAX_N = 100;
const int INF = 10000000;
const int MAX_C = 10;

// XÌîñ
// pair <cèÌø, XÌÔ>
typedef pair<int, int > T;

// n_Ìîñ
// pair <Å¬RXg,n_Ìîñ>
typedef pair<int, T > P;

// üÍ
int c, n, m, s, d;

// »ÌXÜÅÌÅ¬ÌRXg
// cost[cèÌø][XÌÔ] = ïp
int cost[MAX_C + 1][MAX_N];

// ùÉÅKlªèÏÝ©Ç¤©
bool flag[MAX_C + 1][MAX_N];

// HüÌîñ
// line[n_][I_] = ¿à
int line[MAX_N][MAX_N];

// DPpÌL[
typedef priority_queue <P, vector <P>, greater<P> > Q;
Q dp_q;

// _CNXg@
int dijkstra ()
{
	while (!dp_q.empty() ){
		P p = dp_q.top(); dp_q.pop();
		T &t = p.second;

		// ùÉÅKlªèÏÝ©²×é
		if (flag[t.first][t.second] ){
			continue;
		} // end if
		
		flag[t.first][t.second] = true;

		// ÅIn_
		if (t.second == d ){
			return p.first;
		} // end if

		for (int i = 0; i < n; ++i ){
			// øðgíÈ¢ê
			if (cost[t.first][i] > p.first + line[t.second][i] ){
				cost[t.first][i] = p.first + line[t.second][i];
				dp_q.push (P(p.first + line[t.second][i], T(t.first, i ) ) );
			} // end if

			// øðg¤ê
			if (t.first > 0 && cost[t.first - 1][i] > p.first + line[t.second][i]/2 ){
				cost[t.first - 1][i] = p.first + line[t.second][i]/2;
				dp_q.push (P(p.first + line[t.second][i]/2, T(t.first - 1, i ) ) );
			} // end if
		} // end for
	} // end while

	return INF;
}

void solve()
{
	// ú»
	for (int i = 0; i <= MAX_C; ++i ){
	 	for (int j = 0; j < MAX_N; ++j ){
			cost[i][j] = INF;
			flag[i][j] = false;
		} // end for
	} // end for

	// Jnn_
	dp_q = Q();
	dp_q.push (P(0, T(c, s ) ) );

	// _CNXg@
	int res = dijkstra();

	cout << res << endl;
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.heb", "r", stdin );

	while (cin >> c >> n >> m >> s >> d && c && n && m && s && d){
		s--;d--;
		for (int i = 0; i < MAX_N; ++i ){
			for (int j = 0; j < MAX_N; ++j ){
				line[i][j] = INF;
			} // end for
		} // end for

		for (int i = 0; i < m; ++i ){
			int a, b, f;
			cin >> a >> b >> f;
			a--; b--;
			line[a][b] = f; line[b][a] = f;
		} // end for

		solve();
	} // end while

	return 0;
}

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

#define INFTY 1<<30
#define N 101
#define C 11
#define CONNECTED 1
#define IN_QUEUE 1

using namespace std;

int cost[N][C];
bool vis[N][C];
int W[N][N];
int G[N][N];

class Node{
public:
	Node():id(0),cost(INFTY),c(0){}
	int id;
	int cost;
	int c;
	bool operator>(const Node &t)const{return this->cost > t.cost;}
};

void Dijkstra( Node s ){
	priority_queue< Node,vector<Node>,greater<Node> > pq;

	pq.push( s );

	while( !pq.empty() ){
		Node p = pq.top();

		pq.pop();

		if( vis[p.id][p.c] )
			continue;
		vis[p.id][p.c] = true;
		cost[p.id][p.c] = min( cost[p.id][p.c], p.cost );

		for(int i = 0; i < N; ++i){
			if( G[p.id][i] == CONNECTED ){
				Node np;

				np.id = i;
				np.cost = cost[p.id][p.c] + W[p.id][i];
				np.c = p.c;
				pq.push( np );
				if( p.c > 0 ){
					np.cost = cost[p.id][p.c] + (W[p.id][i]/2);
					np.c = p.c - 1;
					pq.push( np );
				}
			}
		}
	}
}
void ResetGraph(){
	for(int i = 0; i < N; ++i){
		for(int j = 0; j < C; ++j){
			cost[i][j] = INFTY;
			vis[i][j] = false;
		}
		for(int j = 0; j < N; ++j){
			G[i][j] = 0;
			W[i][j] = 0;
		}
	}
}
int main(){
	while( true ){
		int c, n, m, s, d;
		int ans = INFTY;
		Node start;
		
		cin >> c >> n >> m >> s >> d;
		if( !(c||n||m||s||d) )
			break;

		ResetGraph();
		for(int i = 0; i < m; ++i){
			int a, b, f;

			cin >> a >> b >> f;
			G[a][b] = G[b][a] = CONNECTED;
			W[a][b] = W[b][a] = f;
		}
		start.id = s;
		start.cost = 0;
		start.c = c;

		Dijkstra( start );

		for(int i = 0; i < C; ++i){
			ans = min(ans, cost[d][i]);
		}
		cout << ans << '\n';
	}
	return 0;
}

C++: #include<cstdio>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;

typedef pair<int,int> P;

int main(){
  int c,n,m,s,g,a,b,f;
  int cost[101][101];
  int d[11][101];

  while(1){
    scanf("%d %d %d %d %d",&c,&n,&m,&s,&g);
    if(!c && !n && !m && !s && !g)break;

    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
	if(i-j)cost[i][j] = 1<<29;
	else cost[i][j] = 0;
      }
    }

    for(int i=0;i<m;i++){
      scanf("%d %d %d",&a,&b,&f);
      cost[a][b] = f;
      cost[b][a] = f;
    }

    priority_queue<P,vector<P>,greater<P> > q;
    fill(d[0],d[0]+n+1,1<<29);
    d[0][s] = 0;
    q.push(P(0,s));

    while(q.size()){
      P p=q.top();
      q.pop();
      int v = p.second;
      if(d[0][v] < p.first)continue;
      for(int i=1;i<=n;i++){
	if(d[0][i] > d[0][v] + cost[v][i]){
	  d[0][i] = d[0][v] + cost[v][i];
	  q.push(P(d[0][i],i));
	}
      }
    }

    for(int i=1;i<=c;i++){
      fill(d[i],d[i]+n+1,1<<29);
      d[i][s] = 0;
      q.push(P(0,s));

      while(q.size()){
	P p=q.top();
	q.pop();
	int v = p.second;
	if(d[i][v] < p.first)continue;
	for(int j=1;j<=n;j++){
	  if(d[i][j] > d[i][v] + cost[v][j]){
	    d[i][j] = d[i][v] + cost[v][j];
	    q.push(P(d[i][j],j));
	  }
	  if(d[i][j] > d[i-1][v] + cost[v][j]/2){
	    d[i][j] = d[i-1][v] + cost[v][j]/2;
	    q.push(P(d[i][j],j));
	  }
	}
      }
    }

    printf("%d\n",d[c][g]);
  }
}