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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

struct edge { int to, cost; };
struct state {
  int cur, card, cost;
  bool operator<(const state& lhs) const {
    return cost > lhs.cost;
  }
};

typedef pair<int,int> P;

const int kInf = 1 << 28;
int C, N, M, S, D;
vector<edge> es[102];
int d[102][12];

int solve() {
  // init
  for (int i = 0; i < 102; ++i)
    for (int j = 0; j < 12; ++j)
      d[i][j] = kInf;
  // dijkstra
  priority_queue<state> Q;
  d[S][C] = 0;
  Q.push((state){S, C, 0});
  while (!Q.empty()) {
    state s = Q.top(); Q.pop();
    if (d[s.cur][s.card] < s.cost)
      continue;
    rep(i,es[s.cur].size()) {
      const edge& e = es[s.cur][i];
      // without ticket
      if (d[e.to][s.card] > s.cost + e.cost) {
        d[e.to][s.card] = s.cost + e.cost;
        Q.push((state){e.to, s.card, s.cost + e.cost});
      }
      // use ticket
      if (s.card > 0 &&
          d[e.to][s.card - 1] > s.cost + (e.cost / 2)) {
        d[e.to][s.card - 1] = s.cost + (e.cost / 2);
        Q.push((state){e.to, s.card - 1, s.cost + (e.cost / 2)});
      }
    }
  }
  return *min_element(d[D], d[D] + 12);
}

int main() {
  while (scanf("%d%d%d%d%d", &C, &N, &M, &S, &D), C) {
    --S; --D;
    rep(i,N) {
      es[i].clear();
    }
    rep(i,N) {
      int a, b, f;
      scanf("%d%d%d", &a, &b, &f);
      --a; --b;
      es[a].push_back((edge){b, f});
      es[b].push_back((edge){a, f});
    }
    printf("%d\n", solve());
  }
  return 0;
}

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

using namespace std;

const int INF = 10000000;

int city[101][101];

int solve( int s, int d, int c, int n ){
	int dist[11][101];
	int history[11][101];

	for( int i = 0;i < 11;i++ ){
		for( int j = 1;j < 101;j++ ){
			dist[i][j] = INF;
			history[i][j] = 0;
		}
	}


	dist[c][s] = 0;

	typedef pair<int,int> data;
	typedef pair<int,data> graph;
	priority_queue<graph,vector<graph>,greater<graph> > q;

	q.push( graph( 0, data( s, c ) ) );

	while( !q.empty() ){
		graph a = q.top();
		int u = a.second.first;
		int uc = a.second.second;
		q.pop();
		history[uc][u] = 1;

		for( int i = 1;i <= n;i++ ){

			if( history[uc][i] ) continue;
			if( dist[uc][i] > dist[uc][u] + city[u][i] ){
				dist[uc][i] = dist[uc][u] + city[u][i];
				q.push( graph( dist[uc][i], data( i, uc ) ) );
			}

			if( uc && dist[uc - 1][i] > dist[uc][u] + city[u][i] / 2 ){
				dist[uc - 1][i] = dist[uc][u] + city[u][i] / 2;
				q.push( graph( dist[uc - 1][i], data( i, uc - 1 ) ) );
			}
		}
	}
	int answer = INF;
	for( int i = 0;i < 11;i++ ) answer = min( dist[i][d], answer );
	return answer;

}

int main(int argc, char const* argv[])
{
	int c,n,m,s,d;

	while( cin >> c >> n >> m >> s >> d && c != 0 ){
		int a,b,f;
		for( int i = 1;i < 101;i++ ){
			for( int j = 1;j < 101;j++ ){
				city[i][j] = INF * 2;
			}
		}
		for( int i = 0;i < m;i++ ){
			cin >> a >> b >> f;
			city[a][b] = f;
			city[b][a] = f;
		}

		cout << solve( s, d, c, n ) << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#define INF (1e9)
#define N 102
#define C 11
using namespace std;

typedef struct state {
  int cost,pos,ticket;
  state (int a,int b,int c): cost(a),pos(b),ticket(c){} 
  bool operator < (const state &s)const{
    return cost > s.cost;
  }
} state;

void dijkstra(int);
int c,n,d[N][C],M[N][N];
int main(){
  int m,s,ind,a,b,f;
  while(1){
    cin >> c >> n >> m >> s >> ind;
    if(c==0&&n==0&&m==0&&s==0&&ind==0) break;
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
	M[i][j]=INF;
    for(int i=0;i<m;i++){
      cin >> a >> b >> f;
      M[a][b]=M[b][a]=f;
    }
    dijkstra(s);
    cout << d[ind][c] << endl;
  }
  return 0;
}
void dijkstra(int s){
  priority_queue< state > q;
  for(int i=1;i<=n;i++)
    for(int j=1;j<=c;j++)
      d[i][j]=INF;
  d[s][0]=0;
  q.push( (state){0,s,0} );
  while(!q.empty()){
    state r=q.top();
    q.pop();
    int cos=r.cost;
    int pos= r.pos;
    int ticket = r.ticket;

    if(d[pos][ticket]<cos) continue;

    for(int i=1;i<=n;i++){
      if( M[pos][i]==INF)continue;
      
      if(d[ i ][ ticket ] > d[pos][ticket] + M[pos][i]){

	d[i][ticket]=d[pos][ticket]+M[pos][i];
	q.push((state){d[i][ticket],i,ticket});
      }


      if(ticket == c)continue;
      
      if(d[i][ticket+1] > d[pos][ticket] + M[pos][i] / 2 ){
	d[i][ticket+1]=d[pos][ticket]+M[pos][i]/2;
	q.push((state){d[i][ticket+1],i,ticket+1});
      }
      
    }
  }
}