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)
		}
		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)
		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)
					}
				}
			}
		}
	}
}

C++: #include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(const T x, const S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, const S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, const S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-10;

const int MAX_N = 111;
const int MAX_C = 22;
int c, n, m, s, d;
int t, u, f;
struct Edge{int from, to, cost;};
vector<Edge> g[MAX_N];
int l[MAX_N][MAX_C];

int main()
{
  while(cin >> c >> n >> m >> s >> d, c){
    rep(i, n) g[i].clear();
    rep(i, MAX_N) rep(j, MAX_C) l[i][j] = INF;

    rep(i, m){
      cin >> t >> u >> f;
      g[t - 1].pb((Edge){t - 1, u - 1, f});
      g[u - 1].pb((Edge){u - 1, t - 1, f});
    }

    priority_queue<vi, vector<vi>, greater<vi> > que;
    vi tmp(3);
    tmp[0] = 0;       // ?????¢
    tmp[1] = c;       // ?????°
    tmp[2] = s -  1;  // ??´???
    l[s - 1][c] = 0;
    que.push(tmp);
    while(!que.empty()){
      vi p = que.top();  que.pop();
      int ti = p[1];
      int v = p[2];
      if(l[v][ti] < p[0]) continue;

      vrep(w, g[v]){
        Edge& e = *w;
        if(l[e.to][ti] > l[v][ti] + e.cost){
          l[e.to][ti] = l[v][ti] + e.cost;
          tmp[0] = l[e.to][ti];
          tmp[1] = ti;
          tmp[2] = e.to;
          que.push(tmp);
        }
      }

      if(ti > 0) vrep(w, g[v]){
          Edge& e = *w;
          if(l[e.to][ti - 1] > l[v][ti] + e.cost / 2){
            l[e.to][ti - 1] = l[v][ti] + e.cost / 2;
            tmp[0] = l[e.to][ti - 1];
            tmp[1] = ti - 1;
            tmp[2] = e.to;
            que.push(tmp);
          }
        }
    }

    cout << l[d - 1][0] << endl;
  }

  return 0;
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

using namespace std;

int minimum,min_past_num,num_ticket,num_town,m,start,goal;


struct Info{
    Info(){
        current_town = 0;
        index = 0;
    }
    bool visited[102];
    int current_town,index,costs[102],visited_town[101];
};

struct Data{
	Data(int arg_to,int arg_cost){
		to = arg_to;
		cost = arg_cost;
	}
	int to,cost;
};

vector<Data> V[101];

void func(Info info){

    int sum = 0,limit;

    if(info.current_town == goal || minimum != 2000000000)
    {

    	limit = min(num_ticket,info.index);

    	for(int i = 0; i < limit; i++){
    		sum += info.costs[i]/2;
    	}

    	for(int i = limit; i < info.index; i++){
    		sum += info.costs[i];
    	}

		if(info.current_town == goal){
			minimum = min(minimum,sum);
			return;
		}else{
			if(sum >= minimum){
				return;
			}
		}

    }

    int calc;
    for(int i = 0; i < V[info.current_town].size(); i++){
        if(info.visited[V[info.current_town][i].to] == false){
            Info new_info;
            for(int k = 1; k <= num_town; k++)new_info.visited[k] = info.visited[k];
            new_info.visited[V[info.current_town][i].to] = true;
            new_info.current_town = V[info.current_town][i].to;

            if(info.index == 0 || V[info.current_town][i].cost > info.costs[0]){
            	new_info.costs[0] = V[info.current_town][i].cost;
            	for(int k = 1; k <= info.index; k++){
            		new_info.costs[k] = info.costs[k-1];
            	}
            }else if(V[info.current_town][i].cost <= info.costs[info.index-1]){
            	for(int k = 0; k < info.index; k++){
            		new_info.costs[k] = info.costs[k];
            	}
            	new_info.costs[info.index] = V[info.current_town][i].cost;
            }else{
            	for(calc = 0; info.costs[calc] >= V[info.current_town][i].cost;calc++)new_info.costs[calc] = info.costs[calc];
				new_info.costs[calc] = V[info.current_town][i].cost;
				calc++;
				for(;calc-1 < info.index;calc++)new_info.costs[calc] = info.costs[calc-1];
            }
            new_info.index = info.index+1;
            func(new_info);

        }
    }
}

int main(){

    int from,to,fee;

    while(true){
        scanf("%d %d %d %d %d",&num_ticket,&num_town,&m,&start,&goal);
        if(num_ticket == 0 && num_town == 0 && m == 0 && start == 0 && goal == 0)break;

        minimum = 2000000000;

        for(int i = 1; i <= num_town; i++)V[i].clear();

        for(int i = 0; i < m; i++){
            scanf("%d %d %d",&from,&to,&fee);

            V[from].push_back(Data(to,fee));
            V[to].push_back(Data(from,fee));
        }

        Info info;
        for(int i = 1; i <= num_town;i++)info.visited[i] = false;

        info.current_town = start;
        info.visited[start] = true;

        func(info);

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


    return 0;
}