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 <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({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({dist[w][t], w, t});
      }
      if (t > 0 && cost + weight/2 < dist[w][t-1]) {
        dist[w][t-1] = cost + weight/2;
        Q.push({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({b, f});
      g[b].push_back({a, f});
    }
    int ret = dijkstra();
    printf("%d\n", ret);
  }
  
  return 0;
}

C++: // AOJ 0212
#include<cstdio>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#define rep(i,a) for( int i = 0; i != (a); ++i )

typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;

const int INF = 10000000;

int c, n, m, s, d;	
std::vector<P> G[101];
int dist[101][11];

int dijkstra()
{
	std::fill( (int*)dist, (int*)dist+101, INF );
	dist[s][0] = 0;
	std::priority_queue<PP, std::vector<PP>, std::greater<PP> > pque;
	pque.push( PP( P( s, 0 ), 0 ) );
	while( !pque.empty() )
	{
		PP p = pque.top(); pque.pop();
		int v = p.first.first, cost = p.first.second, tic = p.second;

		if( dist[v][tic] < cost )
			continue;

		rep( i, G[v].size() )
		{
			P e = G[v][i];

			if( dist[e.first][tic] > dist[v][tic]+e.second )
			{
				dist[e.first][tic] = dist[v][tic]+e.second;
				pque.push( PP( P( e.first, dist[e.first][tic] ), tic ) );
			}
		}

		if( tic < c ) rep( i, G[v].size() )
		{
			P e = G[v][i];

			if( dist[e.first][tic+1] > dist[v][tic]+e.second/2 )
			{
				dist[e.first][tic+1] = dist[v][tic]+e.second/2;
				pque.push( PP( P( e.first, dist[e.first][tic+1] ), tic+1 ) );
			}
		}
	}

	return *std::min_element( dist[d], dist[d]+11 );
}

int main()
{
	while( scanf( "%d%d%d%d%d", &c, &n, &m, &s, &d ), c|n|m|s|d )
	{
		rep( i, 101 )
			G[i].clear();

		rep( i, m )
		{
			int a, b, f;
			scanf( "%d%d%d", &a, &b, &f );
			G[a].push_back( P( b, f ) );
			G[b].push_back( P( a, f ) );
		}

		printf( "%d\n", dijkstra() );
	}

	return 0;
}

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

#define INF ((int)1e9)

typedef pair<int, int> Pii;
typedef pair<int, Pii> Piii; // cost, cnum, node

vector<Pii> G[100];
int memo[100][10];

int dijkstra(int src, int dst, int cnum) {
  
  fill(memo[0], memo[0]+1000, INF);
  
  priority_queue<Piii> pq;
  memo[src][cnum] = 0;
  pq.push(Piii(0, Pii(-cnum, src)));
  while(!pq.empty()) {
    const Piii get = pq.top(); pq.pop();
    int cost = get.first;
    int cn = -get.second.first;
    int now = get.second.second;
    
    for(int i=0; i<G[now].size(); i++) {
      int next = G[now][i].first;
      int add_c = G[now][i].second;
      if(memo[next][cn] > cost + add_c) {
	pq.push(Piii(cost+add_c, Pii(-cn, next)));
	memo[next][cn] = cost + add_c;
      }
      
      add_c /= 2;
      if(cn-1>=0 && memo[next][cn-1] > cost + add_c) {
	pq.push(Piii(cost+add_c, Pii(1-cn, next)));
	memo[next][cn-1] = cost + add_c;
      }
    }
  }
  
  return *min_element(memo[dst], memo[dst]+10);
}

int main() {
  int C, N, M, S, D;
  while(cin >> C >> N >> M >> S >> D && (N|M)) {
    for(int i=0; i<N; i++) {
      G[i].clear();
    }
    for(int i=0; i<M; i++) {
      int a, b, c; cin >> a >> b >> c; a--, b--;
      G[a].push_back(make_pair(b, c));
      G[b].push_back(make_pair(a, c));
    }
    
    S --, D --;
    cout << dijkstra(S, D, C) << endl;
  }
  
  return 0;
}