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 <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

typedef pair<int, pair<int, int>> STATE;

const int INF = INT_MAX / 4;

int main(void) {
	int c, n, m, s, d;

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

		VVI es(n, VI(n, INF));
		for (int i = 0; i < m; i++) {
			int a, b, f;
			cin >> a >> b >> f;
			es[a - 1][b - 1] = f;
			es[b - 1][a - 1] = f;
		}

		VVI distance(n, VI(c + 1, INF));	// node, ticket
		distance[s][c] = 0;
		priority_queue<STATE, vector<STATE>, greater<STATE>> q; // cost, node, ticket
		q.push(STATE(0, make_pair(s, c)));

		while (q.size()) {
			int cost = q.top().first;
			int node = q.top().second.first;
			int ticket = q.top().second.second;
			q.pop();

			if (cost > distance[node][ticket]) {
				continue;
			}

			for (int i = 0; i < n; i++) if (es[node][i] != INF) {
				int next_cost;

				// not use ticket
				next_cost = distance[node][ticket] + es[node][i];
				if (distance[i][ticket] > next_cost) {
					distance[i][ticket] = next_cost;
					q.push(STATE(next_cost, make_pair(i, ticket)));
				}

				// ticket - 1
				if (ticket) {
					next_cost = distance[node][ticket] + es[node][i] / 2;
					if (distance[i][ticket - 1] > next_cost) {
						distance[i][ticket - 1] = next_cost;
						q.push(STATE(next_cost, make_pair(i, ticket - 1)));
					}
				}
			}
		}

		cout << *min_element(distance[d].begin(), distance[d].end()) << endl;
	}

	return 0;
}

C++: //Solution for aoj:0212 Highway Express Bus
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
using namespace std;
typedef pair<int, int>P;
typedef pair < P, int > PP;
#define f first
#define s second

//struct S {
//	int cost, to, num;
//	S(int c, int t, int n) : cost(c), to(t), num(n){}
//	bool operator>(const S &s) const {
//		return cost > s.cost;
//	}
//};

const int INF = 1 << 29;
int c, n, m, s, d, ans;
int tocost[1000][100];
vector<P> town[1000];


void dijkstra(){
	priority_queue<PP, vector<PP>, greater<PP> > pq;
	pq.push({ { 0, s }, c });
	while (!pq.empty()){
		PP a = pq.top();
		pq.pop();
		for (int i = 0; i < town[a.f.s].size(); i++){
			int tt = town[a.f.s][i].f, cc = town[a.f.s][i].s;
			if (tocost[tt][a.s] > cc + a.f.f){
				tocost[tt][a.s] = cc + a.f.f;
				pq.push({ { cc + a.f.f, tt }, a.s });
			}
			if (a.s&&tocost[tt][a.s-1] > cc/2 + a.f.f){
				tocost[tt][a.s-1] = cc/2 + a.f.f;
				pq.push({ { cc / 2 + a.f.f, tt }, a.s - 1 });
			}
		}
	}
}
	int main(){
		while (cin >> c >> n >> m >> s >> d&&c&&n&&m&&s){
			for (int i = 0; i < 1000; i++)
				fill(tocost[i], tocost[i] + 100, INF);
			tocost[s][c] = 0;
			ans = INF;
			for (int i = 0; i < 1000; i++)
				town[i].clear();
			for (int i = 0; i < m; i++){
				int a, b, c;
				cin >> a >> b >> c;
				town[a].push_back({ b, c });
				town[b].push_back({ a, c });
			}
			dijkstra();
			for (int i = 0; i <= c; i++)
				ans = min(ans, tocost[d][i]);
			cout << ans << endl;
		}
		return 0;
	}

C++: #include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>

using namespace std;

int c,n,m,s,d;
vector<pair<int,int> >  v[101];
int dp[101][11];

int inf = 1111111111;

typedef pair<pair<int,int>,int> p;

void dijkstra(int s,int ticket){
  priority_queue<p,vector<p>,greater<p> > que;
  
  fill((int *)dp,(int *)dp+101*11,inf);
  dp[s][0] = 0;
  que.push(make_pair(make_pair(0,s),0));

  while(!que.empty()){
    p x = que.top();
    que.pop();
    int V = (x.first).second;
    if(dp[V][x.second] < (x.first).first)
      continue;
    for(int i = 0;i<v[V].size();i++){
      pair<int,int> tmp = v[V][i];
      if(dp[tmp.first][x.second] > dp[V][x.second] + tmp.second){
	dp[tmp.first][x.second] = dp[V][x.second] + tmp.second;
	que.push(make_pair(make_pair(dp[tmp.first][x.second],tmp.first),x.second));
      }

      if(x.second < ticket && dp[tmp.first][x.second+1] > dp[V][x.second] + tmp.second/2) {
	//cout<<"a"<<endl;
	dp[tmp.first][x.second+1] = dp[V][x.second] + tmp.second/2;
	que.push(make_pair(make_pair(dp[tmp.first][x.second+1],tmp.first),x.second+1));
      }		

    }

  }
}


int main(){

  while(cin>>c>>n>>m>>s>>d){
    if(c==0&&n==0&&m==0&&s==0&&d==0)
      break;
  
    for(int i = 0;i<101;i++){
      v[i].clear();
    }
    s--;
    d--;
    for(int i = 0;i<m;i++){
      int a,b,f;
      cin>>a>>b>>f;
      a--;b--;
      v[a].push_back(make_pair(b,f));
      v[b].push_back(make_pair(a,f));
    }
    dijkstra(s,c);
    int ans = inf;
    /*
    for(int i = 0;i<=c;i++){
      ans = min(ans,dp[d][i]);
    }
    */
    /*
    for(int i = 0;i<=c;i++){
      for(int j = 0;j< n;j++){
	cout<<dp[j][i]<<" ";
      }
      cout<<endl;
    }
    */
    cout<<dp[d][c]<<endl;
  }

  return 0;
}