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
}

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>

const int MAX_N = 100, MAX_C = 11, INF = 1 << 24;
int dist[MAX_C][MAX_N], used[MAX_C][MAX_N], cost[MAX_N][MAX_N];
int c, n, m, s, d;

void dijkstra(int s){
	for(int i=0;i<MAX_C;i++){
		std::fill(dist[i], dist[i]+MAX_N, INF);
		std::fill(used[i], used[i]+MAX_N, 0);
	}

	dist[0][s] = 0;

	while(true){
		int u = -1, v;
		for(int i=0;i<=c;i++){
			for(int j=0;j<n;j++){
				if(!used[i][j] && (u == -1 || dist[i][j] < dist[u][v]))
					u = i, v = j;
			}
		}

		if(u == -1)break;
		used[u][v] = 1;


		for(int i=0;i<n;i++){
			dist[u][i] = std::min(dist[u][i], dist[u][v] + cost[v][i]);
			if(u+1 < n)
				dist[u+1][i] = std::min(dist[u+1][i], dist[u][v] + cost[v][i] / 2);
		}
	}
}

int main(){
	while(std::cin >> c >> n >> m >> s >> d, c){

		for(int i=0;i<MAX_C;i++){
			std::fill(cost[i], cost[i]+MAX_C, INF);
		}

		for(int i=m;i--;){
			int a, b, f;
			std::cin >> a >> b >> f;
			cost[a-1][b-1] = f;
			cost[b-1][a-1] = f;
		}

		dijkstra(s-1);

		int res = INF;
		for(int i=0;i<=c;i++){
			res = std::min(res, dist[i][d-1]);
		}

		std::cout << res << std::endl;
	}
}

C++: #include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int c, n, m, s, d, a, b, f, dp[11][100]; vector<pair<int, int> > G[100];
int main() {
	while(scanf("%d%d%d%d%d", &c, &n, &m, &s, &d), s--, d--, c) {
		for(int i = 0; i < n; i++) G[i].clear();
		for(int i = 0; i <= c; i++) {
			for(int j = 0; j < n; j++) dp[i][j] = 1000000000;
		}
		dp[0][s] = 0;
		for(int i = 0; i < m; i++) {
			scanf("%d%d%d", &a, &b, &f);
			G[a - 1].push_back(make_pair(b - 1, f));
			G[b - 1].push_back(make_pair(a - 1, f));
		}
		priority_queue<vector<int> > que; que.push({0, s, 0});
		while(!que.empty()) {
			vector<int> v1 = que.top(); que.pop();
			for(int i = 0; i < G[v1[1]].size(); i++) {
				int u = G[v1[1]][i].first, w = G[v1[1]][i].second;
				if(dp[v1[2]][u] > dp[v1[2]][v1[1]] + w) {
					dp[v1[2]][u] = dp[v1[2]][v1[1]] + w;
					que.push({-dp[v1[2]][u], u, v1[2]});
				}
				if(v1[2] < c && dp[v1[2] + 1][u] > dp[v1[2]][v1[1]] + w / 2) {
					dp[v1[2] + 1][u] = dp[v1[2]][v1[1]] + w / 2;
					que.push({-dp[v1[2] + 1][u], u, v1[2] + 1});
				}
			}
		}
		int ret = 1000000000;
		for(int i = 0; i <= c; i++) ret = min(ret, dp[i][d]);
		printf("%d\n", ret);
	}
}

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

#define reep(i,n,m) for(int i=(n);i<(m);i++)
#define rep(i,n) reep(i,0,n)

using namespace std;

class Edge{
public:
    int to;
    int cost;
    Edge(int to,int cost):to(to),cost(cost){}
};

class Node{
public:
    int used;
    int p;
    int cost;
    Node(int u,int n,int c):used(u),p(n),cost(c){}

    bool operator<(const Node &a)const{
        return cost>a.cost;
    }
};

int main(){
    int c,n,m,s,d;
    while(cin>>c>>n>>m>>s>>d,c+n+m+s+d){

        vector<Edge> edge[101];
        rep(i,m){
            int a,b,f;
            cin >> a >> b >> f;
            edge[a].push_back(Edge(b,f));
            edge[b].push_back(Edge(a,f));
        }

        priority_queue<Node> Q;
        Q.push(Node(0,s,0));

        bool used[101][11] = {0};

        while(!Q.empty()){
            Node node = Q.top();Q.pop();
            if(used[node.p][node.used]){
                continue;
            }
            used[node.p][node.used] = true;

            int p = node.p;

            if(p==d){
                cout << node.cost << endl;
                break;
            }

            rep(i,edge[p].size()){
                Edge e = edge[p][i];
                int next = e.to;
                int cost = node.cost + e.cost;
                Q.push(Node(node.used,next,cost));
                if(node.used<c){
                    cost = node.cost + e.cost/2;
                    Q.push(Node(node.used+1,next,cost));
                }
            }
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
using namespace std;

#define MAX 10000000
#define n_MAX 101
#define c_MAX 11

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] = f;
      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;
      }
    }
    t[c][s] = 0;

    for ( long long int j = c; j >= 0; j-- ) {

      priority_queue< pair< int, int >, vector< pair< int, int > >, greater< pair< int, int > > > q;

      for ( long long int i = 1; i <= n; i++ ) {
	if ( t[j][i] < MAX ) {
	  q.push( make_pair( t[j][i], i ) );
	}
      }

      while( q.size() > 0 ) {

	pair< int, int > p;
	p = q.top();
	q.pop();
	long long int next = p.second;
	if ( t[j][next] < p.first ) continue;

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

	  if ( l[next][i] == 0 ) continue;
	  if ( t[j][i] > t[j][next] + l[next][i] ) {
	    t[j][i] = t[j][next] + l[next][i];
	    q.push( make_pair( t[j][i], i ) );
	  }
	  if ( j > 0 ) {
	    t[j - 1][i] = min( t[j - 1][i], t[j][next] + l[next][i] / 2 );
	  }

	}

      }

    }

    long long int ans = MAX;

    for ( long long int i = 0; i <= c; i++ ) {
      ans = min( ans, t[i][d] );
    }

    cout << ans << endl;

  }

  return 0;

}