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 <queue>
#include <map>
#include <cassert>
#include <algorithm>
using namespace std;
typedef pair<int, int> edge;
struct state{
  int cost, coupon, station;
  state(int cost_, int coupon_, int station_):cost(cost_), coupon(coupon_), station(station_){}
  bool operator< (const state &s) const{
    if(cost == s.cost){
      return coupon > s.coupon;
    }
    return cost > s.cost;
  }
};
int djikstra(vector<vector<edge> > graph, int start, int goal, int coupon){
  priority_queue<state> pq;
  pq.push(state(0, coupon, start));
  bool visited[coupon][graph.size()];
  fill_n((bool*)visited, (coupon+1) * graph.size(), false);
  while(!pq.empty()){
    state cur = pq.top(); pq.pop();
    //cout << cur.station << ": " << cur.cost << ": " << cur.coupon << endl;
    if(visited[cur.coupon][cur.station]){
      continue;
    }
    if(cur.station == goal){
      return cur.cost;
    }
    visited[cur.coupon][cur.station] = true;
    for(int i = 0; i < graph[cur.station].size(); ++i){
      int to = graph[cur.station][i].first;
      int c = graph[cur.station][i].second;
      if(cur.coupon > 0){
        pq.push(state(cur.cost+c/2, cur.coupon-1, to));
      }
      pq.push(state(cur.cost+c, cur.coupon, to));
    }
  }
  assert(false);
}
int main(){
  int c, n, m, s, d;
  while(true){
    cin >> c >> n >> m >> s >> d;
    if((c|n|m|s|d) == 0){
      break;
    }
    vector<vector<edge> > graph(n+1, vector<edge>());
    for(int i = 0; i < m; ++i){
      int a, b, f;
      cin >> a >> b >> f;
      graph[a].push_back(make_pair(b, f));
      graph[b].push_back(make_pair(a, f));
    }
    cout << djikstra(graph, s, d, c) << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;//cost, v, ticket
struct edge{
  int to, cost;
};

int main(int argc, char *argv[]){
  int c, n, m, s, d;
  while(std::cin >> c >> n >> m >> s >> d, n){
    s--;d--;
    vector<vector<edge> > g(n);
    for (int i = 0; i < m; i++) {
      edge e;
      int from;
      std::cin >> from >> e.to >> e.cost;
      e.to--;from--;
      g[from].push_back(e);
      g[e.to].push_back((edge){from, e.cost});
    }
    vector<vector<int> > dp(c + 1, vector<int>(n, 1e9));
    dp[0][s] = 0;
    priority_queue<piii, vector<piii>, greater<piii> > que;
    que.push(piii(0, pii(s, 0)));
    while(!que.empty()){
      int cost   = que.top().first;
      int v      = que.top().second.first;
      int ticket = que.top().second.second;
      que.pop();
      for (int i = 0; i < g[v].size(); i++) {
        edge e = g[v][i];
        if(dp[ticket][e.to] > dp[ticket][v] + e.cost){
          dp[ticket][e.to] = dp[ticket][v] + e.cost;
          que.push(piii(dp[ticket][e.to], pii(e.to, ticket)));
        }
        if(ticket + 1 <= c &&
           dp[ticket + 1][e.to] > dp[ticket][v] + e.cost/2){
          dp[ticket + 1][e.to] = dp[ticket][v] + e.cost/2;
          que.push(piii(dp[ticket + 1][e.to],
                        pii(e.to, ticket + 1)));
        }
      }
    }
    std::cout << dp[c][d] << std::endl;
  }
  return 0;
}

C++: #include <iostream>
#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)
#define eacha(e,c) for(auto &e:c)

struct edge {
    int from,to,cost;
};

vector<edge> E;
array<array<int,11>,101> dp;
int c,n,m,s,d;

int main(){
    while(cin>>c>>n>>m>>s>>d, c|n|m|s|d){
        vector<edge>(m*2).swap(E);
        rep(i,m) cin>>E[i].from>>E[i].to>>E[i].cost;
        rep(i,c+1){
            dp[i].fill(1<<30);
            dp[i][s]=0;
            bool end;
            while(1){
                end=1;
                eacha(e,E){
                    rep(a,2){
                        int nd;
                        if(i==0) nd=dp[i][e.from]+e.cost;
                        else nd=min(dp[i-1][e.from]+e.cost/2,
                                    dp[i][e.from]+e.cost);
                        if(nd<dp[i][e.to]){
                            dp[i][e.to]=nd;
                            end=false;
                        }
                        swap(e.to,e.from);
                    }
                }
                if(end) break;
            }
        }
        cout<<dp[c][d]<<endl;
    }
}