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 <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)

const int INF = 1 << 24;
const int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};

typedef unsigned long long ull;

struct Edge{
    int to, cost;
};

int C, N, M, S, D;
int cost[110][110];
int d[110][20], used[110][20];

void dijkstra(){
    REP(i, 110){
        REP(j, 20){
            d[i][j] = INF;
            used[i][j] = 0;
        }
    }

    d[S][0] = 0;

    while(1){
        int u = -1, v = -1;
        REP(i, N){
            REP(j, C+1){
                if(!used[i][j] && (u == -1 || d[u][v] > d[i][j])){u = i; v = j;}
            }
        }

        if(u == -1){break;}
        used[u][v] = 1;

        REP(i, N){
            if(v+1 <= C){
                d[i][v+1] = std::min(d[i][v+1], d[u][v] + cost[u][i] / 2);
            }
            d[i][v] = std::min(d[i][v], d[u][v] + cost[u][i]);
        }
    }
}

int main(){
    while(std::cin >> C >> N >> M >> S >> D, C){
        S--; D--;

        REP(i, 110){
            REP(j, 110){
                cost[i][j] = INF;
            }
        }

        REP(i, M){
            int from, to, co;
            std::cin >> from >> to >> co;
            from--; to--;
        
            cost[from][to] = co;
            cost[to][from] = co;
        }

        dijkstra();

        int res = INF;
        REP(i, C+1){
            res = std::min(res, d[D][i]);
        }

        std::cout << res << std::endl;
    }
}

C++: #include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <utility>
#include <functional>
using namespace std;

#define INF 19980725

/** 割引券の枚数 */
static int c;
#define C 10
/** 町の数 */
static int n;
#define N 100
/** 路線数 */
static int m;
#define M 500
/** 出発地 */
static int s;
/** 目的地 */
static int d;

/** 路線情報 */
static int map[ N ][ N ];

/** 各探索先における状態 */
struct stat
{
  /** 到達先の町 */
  int pos;
  /** 現時点までの費用 */
  int cost;
  /** 割引券の残枚数 */
  int rem;

  stat (
    )
  {
    this->cost = INF;
    this->rem  = 0;
  }
  stat (
    int pos,
    int cost,
    int rem
    )
  {
    this->pos  = pos;
    this->cost = cost;
    this->rem  = rem;
  }
  bool operator> (
    const stat &a
    )
  const
  {
    return ( cost > a.cost
          || ( cost == a.cost && rem < a.rem ) );
  }
};

int
main (
  int   argc,
  char *argv[ ]
  )
{
  for ( ; ; )
  {
    priority_queue<stat, vector<stat>, greater<stat> > lis;
    int stats[ C + 1 ][ N ];
    int res;
    int i, j;

    /* 基本情報読み込み */
    scanf ( "%d%d%d%d%d", &c, &n, &m, &s, &d );
    if ( !( c | n | m | s | d ) ) break ;
    --s; --d;

    /* 路線情報初期化 */
    for ( i = 0; i < n; ++i )
    for ( j = 0; j < n; ++j )
      map[ i ][ j ] = INF;

    /* 路線情報読み込み */
    for ( i = 0; i < m; ++i )
    {
      int a, b, f;

      scanf ( "%d%d%d", &a, &b, &f );
      --a; --b;
      map[ a ][ b ] =
      map[ b ][ a ] = f;
    }

    /* s->d に対してダイクストラ法を適用 */
    for ( i = 0; i <= c; ++i )
    for ( j = 0; j < n; ++j )
      stats[ i ][ j ] = INF;
    lis.push ( stat ( s, 0, c ) );
    while ( !lis.empty ( ) )
    {
      const stat st = lis.top ( );
      lis.pop ( );

      /* 既に探索済みであれば処理しない */
      if ( stats[ st.rem ][ st.pos ] != INF )
        continue ;
      stats[ st.rem ][ st.pos ] = st.cost;

      for ( i = 0; i < n; ++i )
      {
        /* st.pos からi への経路が存在しなければ処理しない */
        if ( map[ st.pos ][ i ] == INF )
          continue ;

        /* 隣接する町の探索を予約する．割引券が使えればその探索も予約する． */
        lis.push ( stat ( i, st.cost + map[ st.pos ][ i ], st.rem ) );
        if ( st.rem > 0 )
          lis.push ( stat ( i, st.cost + map[ st.pos ][ i ] / 2, st.rem - 1 ) );
      }
    }

    /* s->d への最小費用を算出 */
    res = INF;
    for ( i = 0; i <= c; ++i )
      res = min ( res, stats[ i ][ d ] );
    printf ( "%d\n", res );
  }

  return ( EXIT_SUCCESS );
}

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

using namespace std;

struct P {
	int from, cost, coupon;

	bool operator >(const P& p) const {
		return cost > p.cost;
	}
};

int ecost[101][101];
int ccost[101][11];
int c, n, m, s, d;
int i;

int main() {
	while(cin >> c >> n >> m >> s >> d, c|n|m|s|d) {
		fill_n((int *)ecost, 101*101, -1);
		fill_n((int *)ccost, 101*11, 1e8);
		for(i=0; i<m; i++){
			int a, b, f;
			cin >> a >> b >> f;
			ecost[a][b] = f;
			ecost[b][a] = f;
		}
		priority_queue<P, vector<P>, greater<P>> q;
		q.push((P){s, 0, 0});
		int dcost;
		while(!q.empty()){
			P p = q.top(); q.pop();
			// goal
			if(p.from == d) {
				dcost = p.cost;
				break;
			}
			//
			for(i=0; i<n+1; i++){ // i:to
				if(ecost[p.from][i] != -1){
					if(p.cost + ecost[p.from][i] < ccost[i][p.coupon]){
						q.push((P){i, p.cost + ecost[p.from][i], p.coupon});
					}
					if(p.coupon+1 <= c) {
						if(p.cost + ecost[p.from][i]/2 < ccost[i][p.coupon+1]){
							q.push((P){i, p.cost + ecost[p.from][i]/2, p.coupon+1});
						}
					}
				}
			}
		}
		cout << dcost << endl;
	}
	return 0;
}