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 <array>
#include <vector>

using namespace std;
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define eacha(e,c) for(auto &e:c)

struct edge {
    int from,to,cost;
};

vector<edge> E;
array<array<int,11>,101> dp;
int c,n,m,s,d;

int main(){
    while(cin>>c>>n>>m>>s>>d, c|n|m|s|d){
        vector<edge>(m*2).swap(E);
        rep(i,m) cin>>E[i].from>>E[i].to>>E[i].cost;
        rep(i,c+1){
            dp[i].fill(1<<30);
            dp[i][s]=0;
            bool end;
            while(1){
                end=1;
                eacha(e,E){
                    rep(a,2){
                        int nd;
                        if(i==0) nd=dp[i][e.from]+e.cost;
                        else nd=min(dp[i-1][e.from]+e.cost/2,
                                    dp[i][e.from]+e.cost);
                        if(nd<dp[i][e.to]){
                            dp[i][e.to]=nd;
                            end=false;
                        }
                        swap(e.to,e.from);
                    }
                }
                if(end) break;
            }
        }
        cout<<dp[c][d]<<endl;
    }
}

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

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)

struct edge{
    int to, cost;
};

typedef pair<int, pair<int, int> > pii; // distance, edge, ticket

int INF = 10e8;
int c, n, m, s, d;

int dis[101][11];

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

        if(n==0) break;

        vector<edge> g[101];
        REP(i, m){
            int a, b, f;
            cin >> a >> b >> f;
            edge ae;
            ae.to = b;
            ae.cost = f;
            g[a].push_back(ae);
            edge be;
            be.to = a;
            be.cost = f;
            g[b].push_back(be);
        }

        priority_queue<pii, vector<pii>, greater<pii> > que;
        REP(i, n+1){
            REP(j, c+1){
                dis[i][j] = INF;
            }
        }
        dis[s][c] = 0;
        pii init = make_pair(0, make_pair(s, c));
        que.push(init);

        while(!que.empty()){
            pii p = que.top();
            que.pop();

            int v = p.second.first;
            int t = p.second.second;
            if(dis[v][t]<p.first) continue;
            REP(i, g[v].size()){
                edge e = g[v][i];
                if(dis[e.to][t] > dis[v][t] + e.cost){
                    dis[e.to][t] = dis[v][t] + e.cost;
                    que.push(pii(make_pair(dis[e.to][t], make_pair(e.to, t))));
                }
                if(t>0 && dis[e.to][t-1] > dis[v][t] + e.cost / 2){
                    dis[e.to][t-1] = dis[v][t] + e.cost / 2;
                    que.push(pii(make_pair(dis[e.to][t-1], make_pair(e.to, t-1))));
                }
            }
        }
        /*
        REP(i, n+1){
            REP(j, c+1){
                cout << dis[i][j] << " ";
            }
            cout << endl;
        }
        */
        int output = INF;
        REP(i, c+1){
            output = min(output, dis[d][i]);
        }
        cout << output << endl;
    }
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<climits>

using namespace std;

typedef pair<int,pair<int,int> >P;

struct Edge{
  int to,cost;
  Edge(int _to, int _cost):to(_to), cost(_cost){};
};

int minCost[101][11];
vector<Edge> edge[101];
static const int INF = INT_MAX;

int c,n,m,s,d;

int dijkstra(void){
  priority_queue<P, vector<P>, greater<P> >que;
  que.push(make_pair(0,make_pair(s,c)));

  for(int i=0;i<101;i++)
    for(int j=0;j<11;j++)
      minCost[i][j]=INF;

  while(!que.empty()){
    P p = que.top();
    que.pop();
    
    for(int i=0;i<edge[p.second.first].size();i++){
      Edge e = edge[p.second.first][i];
      if(p.first+e.cost < minCost[e.to][p.second.second]){
	minCost[e.to][p.second.second] = p.first+e.cost;
	que.push(make_pair(p.first+e.cost,make_pair(e.to,p.second.second)));
      }
    }
    
    if(p.second.second==0)continue;
    
    for(int j=0;j<edge[p.second.first].size();j++){
      Edge e = edge[p.second.first][j];
      if(p.first+e.cost/2 < minCost[e.to][p.second.second-1]){
	minCost[e.to][p.second.second-1] = p.first+e.cost/2;
	que.push(make_pair(p.first+e.cost/2,make_pair(e.to,p.second.second-1)));
      }
    }
  }
  return minCost[d][0];
}

int main(void){
  int a,b,f;

  while(cin >> c >> n >> m >> s >> d,c|n|m|s|d){

    for(int i=0;i<=n;i++)edge[i].clear();

    for(int i=0;i<m;i++){
      cin >> a >> b >> f;
      edge[a].push_back(Edge(b,f));
      edge[b].push_back(Edge(a,f));
    }

    cout << dijkstra() << endl;
  }

  return 0;
}