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>

using namespace std;

const int NODE = 100;
const int TICKET = 10 + 1;
const int INF = 1 << 20;	// 1048576

int E[NODE][NODE];
int cost[TICKET][NODE];
bool used[NODE];

void dijkstra ( int C, int N, int S )
{
	for (int c = 0; c <= C; ++c)
	{
		for (int i = 0; i < N; ++i)
			used[i] = false;
		
		cost[c][S] = 0;
		
		while ( 1 )
		{
			int v = -1;
			for (int i = 0; i < N; ++i)
				if ( !used[i] && ( v == -1 || cost[c][v] > cost[c][i] ))
					v = i;
			if ( v == -1 ) break;
			
			used[v] = true;
			
			if ( c )
				for (int i = 0; i < N; ++i)
				{
					cost[c][i] = min(cost[c][i], min(cost[c][v] + E[v][i] , cost[c-1][v] + E[v][i] / 2));
				}
			else
				for (int i = 0; i < N; ++i)
				{
					cost[c][i] = min(cost[c][i], cost[c][v] + E[v][i]);
				}
		}
	}
}

void init ( void )
{
	for (int i = 0; i < NODE; ++i)
	{
		for (int j = 0; j < NODE; ++j)
			E[i][j] = INF;
		for (int j = 0; j < TICKET; ++j)
			cost[j][i] = INF;
	}	
}

int main ( void )
{
	int c, n, m, s, d;
	
	while ( cin >> c >> n >> m >> s >> d,
		c | n | m | s | d )
	{
		init();
		
		for (int i = 0, a, b, f; i < m; i += 1)
		{
			cin >> a >> b >> f;
			E[a-1][b-1] = E[b-1][a-1] = f;
		}
		
		dijkstra( c, n, s-1 );
		
		cout << cost[c][d-1] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
using namespace std;
 
#define MAX 10000000
#define n_MAX 101
#define c_MAX 11

typedef pair<int, pair<int, int> > edge;

int get_cost(const edge& e){
  return e.first;
}

int get_tickets(const edge& e){
  return -(e.second.first);
}

int get_station(const edge& e){
  return e.second.second;
}

inline edge make_edge(int cost, int tickets, int station){
  return make_pair(cost, make_pair(-tickets, station));
}

int main() {
 
  while( true ) {
    
    long long int c, n, m, s, d;
    cin >> c >> n >> m >> s >> d;
    if ( n == 0 ) break;
    
    long long int l[n_MAX][n_MAX] = {0};
    
    for ( long long int i = 0; i < m; i++ ) {
      long long int a, b, f;
      cin >> a >> b >> f;
      l[a][b] = l[b][a] = f;
    }
 
    long long int t[c_MAX][n_MAX];
    for ( long long int j = 0; j <= c; j++ ) {
      for ( long long int i = 1; i <= n; i++ ) {
	t[j][i] = MAX;
      }
    }
    
    priority_queue<edge, vector<edge>, less<edge> > queue;
    queue.push(make_edge(0, c, s));
    t[c][s] = 0;

    int ans = MAX;
    while(!queue.empty()){
      edge e = queue.top(); queue.pop();

      const int cost = get_cost(e);
      const int tickets = get_tickets(e);
      const int station = get_station(e);
      if(t[tickets][station] > cost){
	continue;
      }else if(station == d){
	ans = min(ans, cost);
      }

      for(long long int next = 1; next <= n; next++){
	if(l[station][next] == 0){
	  continue;
	}
	
	const int next_non_use_cost = cost + l[station][next];
	const int next_use_cost     = cost + l[station][next] / 2;
 
	if(tickets > 0 && t[tickets - 1][next] > next_use_cost){
	  t[tickets - 1][next] = next_use_cost;
	  queue.push(make_edge(next_use_cost, tickets - 1, next));
	}
	
	if(t[tickets][next] > next_non_use_cost){
	  t[tickets][next] = next_non_use_cost;
	  queue.push(make_edge(next_non_use_cost, tickets, next));
	}
      }
    }
 
    cout << ans << endl;
  }
 
  return 0;
 
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <map>
#define INF (1 << 26)
#define fr first
#define sc second
using namespace std;

typedef pair<int,int> S;
typedef pair<S,int> P;
struct edge{
    int to,cost; edge(){}
    edge(int to,int cost):to(to),cost(cost){}
};

int c,n,m,s,d,costed[1024][101];
vector< vector<edge> > info(1024);

void init(){
    for(int i=0;i<1024;i++){
        for(int j=0;j<101;j++) costed[i][j] = INF;
    }
    info.resize(0); info.resize(1024);
}

void add_info(){
    int a,b,f;
    cin >> a >> b >> f;
    info[a].push_back(edge(b,f));
    info[b].push_back(edge(a,f));
}

int Dijkstra(){
    priority_queue<P,vector<P>,greater<P> > que;
    que.push(P(S(0,s),c));  costed[s][c] = 0;
    while(!que.empty()){
        P p = que.top(); que.pop();
        int now = p.fr.sc,c = p.fr.fr,tic = p.sc;
        if(now == d) return c;
        for(int i=0;i<info[now].size();i++){
            edge e = info[now][i];
            if(e.cost + c < costed[e.to][tic]){
                que.push(P(S(e.cost+c,e.to),tic));
                costed[e.to][tic] = e.cost + c;
            }
            if(tic != 0){
                if(e.cost/2 + c < costed[e.to][tic-1]){
                    que.push(P(S(c+e.cost/2,e.to),tic-1));
                    costed[e.to][tic-1] = e.cost/2 + c;
                }
            }
        }
    }
}

int main(){
    while(cin>>c>>n>>m>>s>>d,c||n||m||s||d){
        init();
        for(int i=0;i<m;i++) add_info();
        cout << Dijkstra() << endl;
    }
}