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 <algorithm>
#include <vector>
#include <queue>

using namespace std;

struct edge {
    int to, cost;
    edge() {}
    edge(int to_, int cost_): to(to_), cost(cost_) {}
};

struct state {
    int pos, cost;
    state (){}
    state (int pos_, int cost_): pos(pos_), cost(cost_) {}

    bool operator < (const state& o) const {
        return cost > o.cost;
    }
};

constexpr int INF = 1 << 29;

int C, M, N, S, D;

const int W = 100;
vector<edge> graph[1100];

int min_cost[1100];

bool solve() {
    cin >> C >> N >> M >> S >> D;
    if (C+N+M+S+D == 0) { return false; }
    --S; --D;

    for (int j = 0; j < M; ++j) {
        int a, b, f; cin >> a >> b >> f;
        --a; --b;
        for (int j = 0; j < C; ++j) {
            graph[a+j*W].emplace_back(b+j*W, f);
            graph[b+j*W].emplace_back(a+j*W, f);

            graph[a+j*W].emplace_back(b+(j+1)*W, f/2);
            graph[b+j*W].emplace_back(a+(j+1)*W, f/2);
        }
        graph[a+C*W].emplace_back(b+C*W, f);
        graph[b+C*W].emplace_back(a+C*W, f);
    }

    fill(min_cost, min_cost+1100, INF);
    min_cost[S] = 0;

    priority_queue<state, vector<state>> que;
    que.emplace(S, 0);

    while (!que.empty()) {
        state st = que.top(); que.pop();
        int pos = st.pos;
        int cost = st.cost;
        if (cost > min_cost[st.pos]) { continue; }

        for (edge& e : graph[pos]) {
            int next_cost = cost + e.cost;
            if (next_cost < min_cost[e.to]) {
                min_cost[e.to] = next_cost;
                que.emplace(e.to, next_cost);
            }
        }
    }

    int ans = INF;
    for (int j = 0; j <= C; ++j) {
        ans = min(ans, min_cost[D+j*W]);
    }
    cout << ans << endl;

    return true;
}

int main() {
    for (; solve(); ) ;
    return 0;
}

C++: // AOJ 0212 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0212)
#include <cstdio>
#include <algorithm>
#include <limits>
#include <queue>
#include <utility>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

constexpr int MAX_N = 100, INF = std::numeric_limits<int>::max()>>2;

using P = std::pair<int, std::pair<int, int>>;

struct edge
{
  int to, cost;

  edge( int to, int cost )
  : to(to), cost(cost)
  {}
};

int c, n, m, s, d;
std::vector<edge> G[MAX_N];
int dp[MAX_N][11];

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

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

    std::fill( (int*)dp, (int*)(dp+n), INF );
    
    std::priority_queue<P, std::vector<P>, std::greater<P>> pque;
    pque.push( P( 0, std::make_pair( s, 0 ) ) );
    while( !pque.empty() )
    {
      P p = pque.top(); pque.pop();
      int dist = p.first, v = p.second.first, ticket = p.second.second;

      if( dist > dp[v][ticket] )
        continue;

      for( auto e : G[v] )
      {
        if( dp[e.to][ticket] > dist+e.cost )
        {
          dp[e.to][ticket] = dist+e.cost;
          pque.push( P( dp[e.to][ticket], std::make_pair( e.to, ticket ) ) );
        }
        if( ticket < 10 && dp[e.to][ticket+1] > dist+e.cost/2 )
        {
          dp[e.to][ticket+1] = dist+e.cost/2;
          pque.push( P( dp[e.to][ticket+1], std::make_pair( e.to, ticket+1 ) ) );
        }
      }
    }

    printf( "%d\n", dp[d][c] );
  }

  return 0;
}

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

using namespace std;
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

struct edge {
    int to,cost;
};
struct state {
    int v,d;
    bool operator<(const state& s) const {
        return d>s.d;
    }
};

vector<vector<edge>> G;
array<array<int,11>,101> dp;
priority_queue<state> q;
int c,n,m,s,d;

int main(){
    while(cin>>c>>n>>m>>s>>d, c||n||m||s||d){
        G=vector<vector<edge>>(n+1);
        rep(i,m){
            int f,t,c; cin>>f>>t>>c;
            G[f].push_back({t,c});
            G[t].push_back({f,c});
        }
        rep(i,c+1){
            dp[i].fill(1<<30);
            dp[i][s]=0;
            priority_queue<state>().swap(q);
            q.push({s,0});
            while(q.size()){
                state sta=q.top(); q.pop();
                if(dp[i][sta.v]<sta.d) continue;
                for(edge& e:G[sta.v]){
                    int t;
                    if(i==0) t=dp[0][sta.v]+e.cost;
                    else t=min(dp[i][sta.v]+e.cost,
                               dp[i-1][sta.v]+e.cost/2);
                    if(dp[i][e.to]>t){
                        dp[i][e.to]=t;
                        q.push({e.to,t});
                    }
                }
            }
        }
        cout<<dp[c][d]<<endl;
    }
}