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
}

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)
		for len(pq) != 0 {
			now := heap.Pop(&pq).(*Node)
			if now.NowPosition == d {
				fmt.Println(now.Amount)
				break
			}
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				heap.Push(&pq, next)
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					heap.Push(&pq, next)
				}
			}
		}
	}
}

C++: #include <iostream>
#include <vector>
#include <queue>
using namespace std;

#define INF 100000000

struct edge {
	int to;
	int f;
	edge(int to_, int f_) {
		to = to_; f = f_;
	}
	edge(){}
};
struct status {
	int vertex;
	int cost;
	int c;
	status(int vertex_, int cost_, int c_) {
		vertex = vertex_; cost = cost_; c = c_;
	}
	status(){}
	bool operator<(const status & obj) const {
		if(this->c != obj.c)
			return this->c < obj.c;
		return this->cost > obj.cost;
	}
};

int main() {
	while(true) {
		int c, n, m, s, d;
		cin >> c >> n >> m >> s >> d;
		if(!(c || n || m || s || d))
			break;
		s--; d--;
		vector<vector<edge> > v(n);
		for(int i = 0; i < m; i++) {
			int a, b, f;
			cin >> a >> b >> f;
			a--; b--;
			v[a].push_back(edge(b,f));
			v[b].push_back(edge(a,f));
		}
		priority_queue<status> q;
		int cost[128][16];
		for(int i = 0; i < 128; i++)
			for(int j = 0; j < 16; j++)
				cost[i][j] = INF;
		q.push(status(s, 0, c));
		while(!q.empty()) {
			status cur;
			cur = q.top(); q.pop();

			if(cost[cur.vertex][cur.c] == INF) {
				cost[cur.vertex][cur.c] = cur.cost;
				for(int i = 0; i < v[cur.vertex].size(); i++) {
					if(cost[v[cur.vertex][i].to][cur.c] == INF) {
						q.push(status(v[cur.vertex][i].to, v[cur.vertex][i].f + cur.cost, cur.c));
					}
					if(cur.c > 0 && cost[v[cur.vertex][i].to][cur.c-1] == INF) {
						q.push(status(v[cur.vertex][i].to, v[cur.vertex][i].f / 2 + cur.cost, cur.c - 1));
					}
				}
			}
		}

		int ret = INF;
		for(int i = 0; i <= m; i++) {
			ret = min(ret, cost[d][i]);
		}
		cout << ret << endl;
	}
}

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;


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 << 30;
int c, n, m, s, d, ans;
int tocost[1010][110];
vector<P> town[5001];
priority_queue<S, vector<S>, greater<S> > pq;


void dijkstra(){
	while (!pq.empty()){
		S a = pq.top();
		pq.pop();
		for (int i = 0; i < town[a.to].size(); i++){
			int tt = town[a.to][i].first, cc = town[a.to][i].second;
			if (tocost[tt][a.num] > cc + a.cost){
				tocost[tt][a.num] = cc + a.cost;
				pq.push({ cc + a.cost, tt, a.num });
			}
			if (a.num&&tocost[tt][a.num-1] > cc/2 + a.cost){
				tocost[tt][a.num-1] = cc/2 + a.cost;
				pq.push({ cc/2 + a.cost, tt, a.num-1 });
			}
		}
	}
}
	int main(){
		while (cin >> c >> n >> m >> s >> d&&c){
			for (int i = 0; i < 1010; i++)
				fill(tocost[i], tocost[i] + 110, INF);
			tocost[s][c] = 0;
			ans = INF;
			while (pq.size())
				pq.pop();
			for (int i = 0; i < n; i++)
					town[i].erase(town[i].begin(),town[i].end());
			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 });
			}
			pq.push({ 0, s, c });
			dijkstra();
			for (int i = 0; i <= c; i++)
				ans = min(ans, tocost[d][i]);
			cout << ans << endl;
		}
		return 0;
	}

C++: #include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)

#define MP       make_pair
#define PB       push_back
#define ALL(x)   (x).begin(),(x).end()

const int INF = 1<<29;
const double EPS = 1e-9;
double zero(double d){
  return d < EPS ? 0.0 : d;
}

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


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(7);

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

    int dis[11][101];
    bool used[11][101];
    int cost[101][101];

    REP(i,11){
      fill( dis[i], dis[i]+101, INF );
      fill( used[i], used[i]+101, false );
    }
    dis[0][s] = 0;

    REP(i,101){
      fill( cost[i], cost[i]+101, INF );
      cost[i][i] = 0;
    }

    REP(_t,m){
      int a,b,f;
      cin >> a >> b >> f;
      cost[a][b] = cost[b][a] = f;
    }


    while(true){

      // pick minimum distance in unused
      int mini=-1, minj=0;
      REP(i,c+1){
	REP(j,n+1){
	  if( ! used[i][j] ){
	    if( mini==-1 || dis[mini][minj] > dis[i][j] ){
	      mini = i;
	      minj = j;
	    }
	  }
	}
      }

      if( mini == -1)	break;
      used[mini][minj] = true;

      REP(i,m+1){
	dis[mini][i] = min( dis[mini][i], dis[mini][minj] + cost[minj][i] );
	if( mini + 1 <= c )
	  dis[mini+1][i] = min( dis[mini+1][i], dis[mini][minj] + cost[minj][i]/2 );	  
      }
    }

    int res=INF;
    REP(i,c+1)
      res = min( res, dis[i][d] );

    cout << res << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <algorithm>
 
using namespace std;
 
const int INF = 1000000000;
 
int c, n, m, s, d;
int visited[100][11];
int edge[100][100];
 
 
void dfs(int p, int rem, int cost){
   if(visited[p][rem] < cost) return;
   visited[p][rem] = cost;
   if(p == d) return;
   for(int i=0;i<n;i++){
      if(edge[p][i] == INF) continue;
      if(rem > 0 ) dfs(i, rem-1, cost+(edge[p][i]/2));
      dfs(i, rem, cost+edge[p][i]);
   }
}
 
main(){
   while(cin >> c >> n >> m >> s >> d && (c || n || m || s || d)){
      fill(edge[0], edge[100], INF);
      fill(visited[0], visited[100], INF);
      --s; --d;
      for(int i=0;i<m;i++){
         int a, b, f;
         cin >> a >> b >> f;
         --a; --b;
         edge[a][b] = edge[b][a] = f;
      }
      dfs(s, c, 0);
      int ans = INF;
      for(int i=0;i<c;i++){
         ans = min(ans, visited[d][i]);
      }
      cout << ans << endl;
   }
   return 0;
}