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]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)
					}
				}
			}
		}
		runtime.GC()
	}
}

C++: #include <bits/stdc++.h>
#define F first
#define S second
#define INF 1<<26
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>PP;
typedef struct{
  int to,cost;
}Edge;
int main(){
  int c,n,m,st,go;
  while(1){
    int d[11111][111];
    cin >> c >> n >> m >> st >> go;
    if(c==0 && n==0 && m==0 && st==0 && go==0)break;
    for(int i=0;i<=m;i++){
      for(int j=0;j<=c;j++){
	d[i][j]=INF;
      }
    }
    st--;go--;
    
    int a,b,f;
    vector<Edge> G[1111];
    for(int i=0;i<m;i++){
      cin >> a >> b >> f;
      a--;b--;
      G[a].push_back((Edge){b,f});
      G[b].push_back((Edge){a,f});
    }
    priority_queue<PP,vector<PP>,greater<PP> >pq;
    pq.push(PP(0,P(st,c)));
    d[st][c]=0;
    while(!pq.empty()){
      PP p=pq.top();//左から、コスト、今いる場所、残りのチケット
      pq.pop();
      int now=p.S.F;//今いる場所
      int ti=p.S.S;//チケット
      for(int i=0;i<G[now].size();i++){
	Edge e=G[now][i];
	if(ti){//チケットがあったら
	  if(d[e.to][ti-1] > d[now][ti]+(e.cost/2)){
	    d[e.to][ti-1]=d[now][ti]+(e.cost/2);
	    pq.push(PP(d[e.to][ti-1],P(e.to,ti-1)));
	  }
	}
	if(d[e.to][ti] > d[now][ti]+e.cost){
	  d[e.to][ti]=d[now][ti]+e.cost;
	  // cout << d[e.to][ti] << endl;
	  pq.push(PP(d[e.to][ti],P(e.to,ti)));
	}
      } 
    }
    
    int ans=INF;
    for(int i=0;i<=c;i++){
      ans=min(ans,d[go][i]);
    }
    cout << ans << endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <cstring>
#include <string>
#include <sstream>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<int> > table;

int n;
const int INF = (int)1e7;
const int N = 100;
const int C = 11;
table cost(N);
vector<vector<bool> > used(11);

int dijkstra(int, int, int);

int main(void){
    rep(i, N) cost[i].resize(N);
    rep(i, C) used[i].resize(N);

    for(int c, m, s, g; cin >> c >> n >> m >> s >> g, n; cout << dijkstra(s, g, c) << endl){
        rep(i, N) fill(ALL(cost[i]), INF);
        rep(i, C) fill(ALL(used[i]), false);

        while(m --){
            int a, b, f; cin >> a >> b >> f;
            
            cost[a - 1][b - 1] = cost[b - 1][a - 1] = f;
        }
    }
    
    return 0;
}

int dijkstra(int s, int g, int c){
    table d(c + 1);
    rep(i, c + 1) d[i].resize(n), fill(ALL(d[i]), INF);
    
    d[c][s - 1] = 0;

    while(1){
        int vn = -1, vc = -1;

        rep(i, c + 1) rep(j, n) if(!used[i][j] && (vc == -1 || d[i][j] < d[vc][vn])) vc = i, vn = j;

        if(vc == -1) break;
        used[vc][vn] = true;

        rep(u, n){
            d[vc][u] = min(d[vc][u], d[vc][vn] + cost[vn][u]);
            if(vc) d[vc - 1][u] = min(d[vc - 1][u], d[vc][vn] + cost[vn][u] / 2);
        }
    }

    int ret = INF;
    rep(i, c) ret = min(ret, d[i][g - 1]);
    return ret;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pp;

const int INF = 1e9;

double EPS = 1e-10;


int c, n, m, s, g;



const int MAX_V = 510;

int d[MAX_V][MAX_V][15];
int connect[MAX_V][MAX_V];
int V;
 
void warshall_floyd_init(){
	for(int i = 0; i < V; i++){
		for(int j = 0; j < V; j++){
			for(int k = 0; k <= c; k++){
				if(i == j) d[i][i][k] = 0;
				else d[i][j][k] = INF;
			}
			connect[i][j] = 0;
		}
	}
}

void warshall_floyd() {
				for(int l = c; l>=0; l--){
				//for(int l = 0; l <= c; l++){
	for (int k = 0; k < V; k++) {
		for (int i = 0; i < V; i++) {
			for (int j = 0; j < V; j++) {
					d[i][j][l] = min({d[i][j][l], d[i][k][l] + d[k][j][c], d[i][k][c] + d[k][j][l]});
					if(l>0 && connect[k][j] > 0){
						d[i][j][l-1]=min(d[i][j][l-1], d[i][k][l]+connect[k][j]/2);
					}
					if(l>0 && connect[i][k] > 0){
						d[i][j][l-1]=min(d[i][j][l-1],connect[i][k]/2 + d[k][j][l]);						
					}
				}
			}
		}
	}
}
int main(){
	int a, b, f;
	int ans;
	while(cin>>c>>n>>m>>s>>g){
		if(c == 0 && n == 0 && m == 0 && s == 0 && g == 0) break;
		s--; g--;
		V = n;
		warshall_floyd_init();
		//cout<<d[0][2][0]<<endl;
		for(int i = 0; i < m; i++){
			cin>>a>>b>>f;
			//f/=10;
			a--; b--;
			//d[a][b][c] = d[b][a][c] = f;
			d[a][b][c] = min(d[a][b][c], f);
			d[b][a][c] = min(d[b][a][c], f);
			connect[a][b] = connect[b][a] = f;	
		}
		warshall_floyd();
		int ans = INF;
		for(int i = 0; i <= c; i++) ans = min(ans, d[s][g][i]);
		cout<<ans<<endl;
		//cout<<" "<<d[4][5][2]<<endl;
	}
	
}