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<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#define fr first
#define sc second
using namespace std;
#define INF 10000000
typedef pair<int,int> iiP;
typedef pair<int,iiP> P;
struct edge{
  int to,cost;
  edge(){}
  edge(int to,int cost):to(to),cost(cost){};
};
int c,n,m;
int S,G;
int min_cost[101][10];
bool used[101][10];
vector< vector<edge> > info;
int solve();
int main(){
  while(cin >> c >> n >> m >> S >> G && (c||n||m||S||G)){
  for(int i=0;i<101;i++){
    for(int j=0;j<10;j++){
      min_cost[i][j] = INF;
      used[i][j] = false;
    }
  }
  info.resize(n + 1);
  for(int i=0,a,b,f;i<m;i++){
    cin >> a >> b >> f;
    info[a].push_back(edge(b,f));
    info[b].push_back(edge(a,f));
  }
  cout << solve() << endl;

  for(int i=0;i<=n;i++) info[i].clear();
  }
}
int solve(){
  priority_queue< P,vector<P>,greater<P> > que;

  min_cost[S][c] = 0;
  que.push(P(0,iiP(S,c)));

  while(!que.empty()){
    P p = que.top();
    int cost = p.fr,now = p.sc.fr,KEN = p.sc.sc;
    que.pop();

    if( now == G) return cost;

    if( used[now][KEN] ) continue;
    used[now][KEN] = true;

    for(int i = 0,l = info[now].size();i < l;i++){
      edge e = info[now][i];
      if(cost + e.cost < min_cost[e.to][KEN]){
        min_cost[e.to][KEN] = cost + e.cost;
        que.push(P(min_cost[e.to][KEN],iiP(e.to,KEN)));
      }
      if(KEN != 0){
        if( cost + e.cost/2 < min_cost[e.to][KEN-1] ){
          min_cost[e.to][KEN-1] = cost + e.cost/2;
          que.push(P(min_cost[e.to][KEN-1],iiP(e.to,KEN-1)));
        }
      }
    }
  }
}

C++: #include<iostream>
#include<utility>
#include<vector>
#include<cstdio>
#include<queue>
#include <map>
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
//int in(){int x;cin>>x;return x;}

int main ()
{
	int c,n,m,s,d;
	while(cin>>c>>n>>m>>s>>d&&c&&n&&m&&s&&d)
	{
		int flg[110][20]={};
		int ans =0;
		priority_queue < PP, vector<PP>, greater<PP> > q;
		vector< P > way[110];
		for(int i=0;i<m;i++)
		{
			int a,b,f;
			cin>>a>>b>>f;
			way[a].push_back(P(b,f));
			way[b].push_back(P(a,f));
		}
		PP next;
		q.push(PP(0,P(s,c)));
		while(!q.empty())
		{
			PP now=q.top();q.pop();
			
			flg[now.second.first][now.second.second]=1;
			if(now.second.first==d)
			{
				ans=now.first;
				break;
			}
			
			for(int i=0;i<way[now.second.first].size();i++)
			{
				if(flg[way[now.second.first][i].first][now.second.second]!=1){
				next.first=now.first+way[now.second.first][i].second;
				next.second.first=way[now.second.first][i].first;
				q.push(next);
				}
				if(now.second.second==0)continue;
				if(flg[way[now.second.first][i].first][now.second.second-1]!=1){
				next.first=now.first+way[now.second.first][i].second/2;
				next.second.first=way[now.second.first][i].first;
				next.second.second=now.second.second-1;
				q.push(next);
				}
			}
			
		}
		cout<<ans<<endl;
	}
	
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) string((s).rbegin(), (s).rend())
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

const int INF = 10000;


class V{
public:
	int total;
	int ticket;
	int to;
};
bool operator>(const V &lh, const V &rh){
	return (lh.total > rh.total);
}


int main(){
	while(1){

		int c, n, m, s, d;
		cin >> c >> n >> m >> s >> d;
		if(!(c+n+m+s+d))break;
		n++;
		vector<vector<int> > fare(n, vector<int>(n, INF));
		rep(i, m){
			int a, b, f;
			cin >> a >> b >> f;
			fare[a][b] = fare[b][a] = f;
		}

		vector<vector<int> > best(c+1, vector<int>(n, INF));

		V start;
		start.total = 0;
		start.ticket = 0;
		start.to = s;
		best[0][s] = 0;

		priority_queue<V, vector<V>, greater<V> > q;
		q.push(start);

		while(!q.empty()){
			V p = q.top();
			q.pop();

			if(best[p.ticket][p.to] != p.total) continue;

			rep(i, n){
				if(fare[p.to][i] == INF ) continue;
				V next;
				if(p.total+ fare[p.to][i] < best[p.ticket][i]){
					best[p.ticket][i] = next.total = p.total + fare[p.to][i];
					next.ticket = p.ticket;
					next.to = i;
					q.push(next);
				}
				if(p.ticket < c){
					if(p.total+ fare[p.to][i]/2 < best[p.ticket+1][i]){
						best[p.ticket+1][i] = next.total = p.total + fare[p.to][i]/2;
						next.ticket = p.ticket+1;
						next.to = i;
						q.push(next);
					}
				}
			}
		}

		rep(i, c){
			best[c][d] = min(best[c][d], best[i][d]);
		}

		cout << best[c][d] << endl;
	}

	return 0;
}