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)
		}
		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)
		memo := make(map[Memo]struct{})
		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}] = struct{}{}
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				if _, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok {
					heap.Push(&pq, next)
				}
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					if _, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok {
						heap.Push(&pq, next)
					}
				}
			}
		}
	}
}

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++){
	  int tmp = min(d[i][v] + cost[v][j],d[i-1][v] + cost[v][j]/2);
	  if(d[i][j] > tmp){
	    d[i][j] = tmp;
	    q.push(P(d[i][j],j));
	  }
	}
      }
    }

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

C++: #include <bits/stdc++.h>
using namespace std;

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

int dijkstra(int s, int g, int c, vector<vector<P>> &G){
    vector<vector<int>> dist(110, vector<int>(20, 1e9));
    priority_queue<T, vector<T>, greater<T>> que;
    dist[s][0] = 0;
    que.emplace(0, s, 0);

    while(!que.empty()){
        int ccost, cv, cused;
        tie(ccost, cv, cused) = que.top();
        que.pop();

        if(dist[cv][cused] < ccost) continue;

        for(auto x : G[cv]){
            int nv, ncost;
            tie(nv, ncost) = x;

            if(dist[cv][cused] + ncost < dist[nv][cused]){
                dist[nv][cused] = dist[cv][cused] + ncost;
                que.emplace(dist[nv][cused], nv, cused);
            }

            if(cused < c){
                if(dist[cv][cused] + ncost / 2 < dist[nv][cused+1]){
                    dist[nv][cused+1] = dist[cv][cused] + ncost / 2;
                    que.emplace(dist[nv][cused+1], nv, cused + 1);
                }
            }
        }
    }

    int ans = 1e9;
    for(int i=0; i<=c; i++){
        ans = min(ans, dist[g][i]);
    }

    return ans;
}

int main(){
    while(1){
        int c, n, m, s, d; cin>>c>>n>>m>>s>>d;
        s--, d--;
        if(c == 0) return 0;

        vector<vector<P>> G(n);
        for(int i=0; i<m; i++){
            int a, b, f; cin>>a>>b>>f;
            a--, b--;
            G[a].emplace_back(b, f);
            G[b].emplace_back(a, f);
        }

        cout << dijkstra(s, d, c, G) << endl;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef pair<Edge, int> P;

int dijkstra2(const Graph &g, int c, int s, int t) {
  int n = g.size();
  vector<Weight> dist[c+1];
  REP(i,c+1)
    dist[i].assign(n, INF);
  dist[c][s] = 0;
  priority_queue<P> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(P(Edge(-2, s, 0),c)); !Q.empty(); ) {
    Edge e = Q.top().first;
    int cc = Q.top().second;
    Q.pop();
    FOR(f,g[e.dst]) {
      if (dist[cc][f->dst] > e.weight+f->weight) {
        dist[cc][f->dst] = e.weight+f->weight;
        Q.push(P(Edge(f->src, f->dst, e.weight+f->weight),cc));
      }
      if (cc > 0 && dist[cc-1][f->dst] > e.weight+f->weight/2) {
        dist[cc-1][f->dst] = e.weight+f->weight/2;
        Q.push(P(Edge(f->src, f->dst, e.weight+f->weight/2),cc-1));
      }      
    }
  }
  int res = INF;
  REP(i,c+1) {
    res = min(dist[i][t], res);
  }
  return res;
}

int main() {
  int c,n,m,s,d;
  while(cin>>c>>n>>m>>s>>d,c) {
    s--;d--;
    Graph g(n);
    REP(i,m) {
      int a,b,f;
      cin >> a >> b >> f;
      a--;b--;
      g[a].push_back(Edge(a,b,f));
      g[b].push_back(Edge(b,a,f));
    }
    cout << dijkstra2(g,c,s,d) << endl;
  }
}