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 <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(){
	int c, n, m, s, d;

	cin >> c >> n >> m >> s >> d;
	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> > done(c+1, vector<int>(n, 0));	// 確定済みか
	vector<vector<int> > best(c+1, vector<int>(n, INF));	// 最短

	V start;
	start.total = 0;
	start.ticket = 0;
	start.to = s;

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

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

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

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

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

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <tuple>

using namespace std;

const int INF = 1<<28;
int c, n, m, s, d;
vector<pair<int, int> > g[100];
int dist[100][11];

typedef tuple<int, int, int> node;

int dijkstra() {
  priority_queue<node, vector<node>, greater<node> > Q;
  Q.push(make_tuple(0, s, c));
  dist[s][c] = 0;
  
  while (!Q.empty()) {
    int cost;
    int v;
    int t;
    tie(cost, v, t) = Q.top();
    Q.pop();
    for (auto &edge: g[v]) {
      int w = edge.first;
      int weight = edge.second;
      if (cost + weight < dist[w][t]) {
        dist[w][t] = cost + weight;
        Q.push(make_tuple(dist[w][t], w, t));
      }
      if (t > 0 && cost + weight/2 < dist[w][t-1]) {
        dist[w][t-1] = cost + weight/2;
        Q.push(make_tuple(dist[w][t-1], w, t-1));
      }
    }
  }

  int ret = INF;
  for (int i = 0; i < 11; i++)
    ret = min(ret, dist[d][i]);
  return ret;
}

void init() {
  for (int i = 0; i < 100; i++)
    g[i].clear();
  for (int i = 0; i < 100; i++)
    for (int j = 0; j < 11; j++)
      dist[i][j] = INF;
}

int main(int argc, char *argv[])
{
  for (;;) {
    cin >> c >> n >> m >> s >> d;
    if (!c && !n && !m && !s && !d)
      break;
    --s, --d;
    init();
    for (int i = 0; i < m; i++) {
      int a, b, f;
      cin >> a >> b >> f;
      --a, --b;
      g[a].push_back(make_pair(b, f));
      g[b].push_back(make_pair(a, f));
    }
    int ret = dijkstra();
    printf("%d\n", ret);
  }
  
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-8;
typedef long long ll;
typedef pair<int, int> pint;

typedef pair<int, pint> P;

int dp[101][11];

int main()
{
	int c, n, m, s, d;
	while (scanf("%d%d%d%d%d", &c, &n, &m, &s, &d), c|n|m|s|d)
	{
		vector<pint> edge[101];
		for (int i = 0; i < m; ++i)
		{
			int a, b, f;
			scanf("%d%d%d", &a, &b, &f);
			edge[a].push_back(pint(b, f));
			edge[b].push_back(pint(a, f));
		}

		const int INF = 2 << 25;
		for (int i = 1; i <= n; ++i)
			for (int j = 0; j <= c; ++j)
				dp[i][j] = INF;

		priority_queue<P, vector<P>, greater<P> > q;
		q.push(P(0, pint(s, c)));
		while (!q.empty())
		{
			P e = q.top();
			q.pop();
			int cost = e.first;
			int from = e.second.first;
			int ticket = e.second.second;

			if (cost >= dp[from][ticket])
				continue;
			dp[from][ticket] = cost;

			foreach (it, edge[from])
			{
				int to = it->first;
				int f = it->second;
				q.push(P(cost + f, pint(to, ticket)));
				if (ticket)
					q.push(P(cost + f/2, pint(to, ticket-1)));
			}
		}

		printf("%d\n", *min_element(dp[d], dp[d]+c+1));
	}

	return 0;
}