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 <queue>
#include <vector>
#include <functional>
#include <algorithm>
#define MAX_V 100
#define INF 10000000
using namespace std;

struct edge{
  int to,cost;
};

typedef pair<int,int> P; //firstは最短経路,secondは頂点番号

vector<edge> G[MAX_V];
int vertexes,edges;
int d[MAX_V][MAX_V];

void dijkstra(int start,int tickets){
  priority_queue<P,vector<P>,greater<P> > que;
  for(int i=0;i<vertexes;i++) d[tickets][i] = INF;
  d[tickets][start] = 0;
  que.push(P(0,start));

  while(!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.second; 
    if(d[tickets][v] < p.first) continue; //異なる2経路のコストで高い方は無視
    for(int i=0;i<G[v].size();i++){
      edge e = G[v][i];
      int minimum = (tickets==0 ? d[tickets][v] + e.cost: min(d[tickets][v] + e.cost, d[tickets-1][v] + e.cost/2));
      if(d[tickets][e.to] > minimum){
        d[tickets][e.to] = minimum;
        que.push( P(d[tickets][e.to],e.to) );
      }
    }
  }
}

int main(){
  int discounts,start,destination;
  while(cin >> discounts >> vertexes >> edges >> start >> destination){
    for(int i=0;i<edges;i++){
      int a,b,fee;
      cin >> a >> b >> fee;
      a--; b--;

      edge E;
      E.to = b;
      E.cost = fee;
      G[a].push_back(E);

      E.to = a;
      G[b].push_back(E);
    }
    start--; destination--;
    for(int i=0;i<=discounts;i++) dijkstra(start,i);
    cout << d[discounts][destination] << endl;
    for(int i=0;i<MAX_V;i++) G[i].clear();
  }
  return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

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

#ifdef DEBUGLOCAL
#define debug cout
#else
stringstream __ss__;
#define debug __ss__
#endif

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) debug << *i << " "; debug << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;i--)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);i--)
#define rep0(i,n) for(i=0;i<(n);++i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[]={1,-1,0,0,1,-1,1,-1,0};
const int dy[]={0,0,1,-1,1,-1,-1,1,0};

int c,n,m,s,d;
int edge[111][111];
int cost[11][111];

int main() {
	IL{
		cin>>c>>n>>m>>s>>d;
		--s,--d;
		if(c==0)break;
		int fr,to,co;
		rep(i,111)rep(j,111)edge[i][j]=INF;
		rep(i,m){
			cin>>fr>>to>>co;
			--fr,--to;
			chmin(edge[fr][to],co);
			chmin(edge[to][fr],co);
		}
		rep(i,11)rep(j,111)cost[i][j]=INF;
		priority_queue<pair<int,pint> > que;
		que.push(MP(0,MP(0,s)));
		while(!que.empty()){
			pair<int,pint> p;
			p=que.top();
			que.pop();
			if(cost[p.second.first][p.second.second]<=p.first)continue;
			if(p.second.first>c)continue;
			cost[p.second.first][p.second.second]=p.first;
			rep(i,n){
				if(edge[p.second.second][i]==INF)continue;
				pair<int,pint> next=p;
				next.first+=edge[p.second.second][i]/2;
				++next.second.first;
				next.second.second=i;
				que.push(next);
				next.first+=edge[p.second.second][i]/2;
				--next.second.first;
				que.push(next);
			}
		}
		int res=INF;
		repn(i,0,n){
			chmin(res,cost[i][d]);
		}
		cout<<res<<endl;
	}
	return 0;
}

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

using namespace std;

struct NODE{
	int to, cost, ticket;
	NODE(int to, int cost, int ticket) : to(to), cost(cost), ticket(ticket) {}
	NODE() {}
};

// 小さい順になる（らしい
bool operator < (const NODE &a, const NODE &b)
{
	return a.cost > b.cost;
}

int main(void)
{
	int c, n, m, s, d;
	while (cin >> c >> n >> m >> s >> d, n){
		s--;
		d--;
		vector <NODE> edge[100];
		for (int i = 0; i < m; i++){
			int a, b, f;
			cin >> a >> b >> f;
			a--;
			b--;
			// むこうぐらふ
			edge[a].push_back(NODE(b, f, -1));
			edge[b].push_back(NODE(a, f, -1));
		}
		// done[町][チケット]
		// その町でチケットが n 残ってるときに訪れたかどうか
		bool done[110][15] = {};
		priority_queue <NODE> Q;
		// すたーと，こすと0，ちけっと
		Q.push(NODE(s, 0, c));
		while (Q.size()){
			NODE q = Q.top();
			Q.pop();
			if (done[q.to][q.ticket]) continue;
			else done[q.to][q.ticket] = true;
			if (q.to == d){
				cout << q.cost << endl;
				break;
			}
			for (int i = 0; i < edge[q.to].size(); i++){
				Q.push(NODE(edge[q.to][i].to, q.cost + edge[q.to][i].cost, q.ticket));
				if (q.ticket) Q.push(NODE(edge[q.to][i].to, q.cost + (edge[q.to][i].cost / 2), q.ticket-1));
			}
		}
	}

	return 0;
}