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>
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;
int c,n,m,s,d;
vector<P> G[101];
int cost[101][11];
int INF=10000000;

int dijkstra(int s){
	priority_queue<PP, vector<PP>, greater<PP> >que;
	for(int i=0;i<=100;i++){
		for(int j=0;j<=10;j++){
			cost[i][j]=INF;
		}
	}
	cost[s][0]=0;
	que.push(PP(P(s,0),0));
	while(que.size()){
		PP p=que.top();que.pop();
		int v=p.first.first,d=p.first.second,k=p.second;
		if(cost[v][k]<d)continue;
		for(int i=0;i<G[v].size();i++){
			P e=G[v][i];
			if(cost[e.first][k]>cost[v][k]+e.second){
				cost[e.first][k]=cost[v][k]+e.second;
				que.push(PP(P(e.first,cost[e.first][k]),k));
			}
		}
		if(k<c)for(int i=0;i<G[v].size();i++){
			P e=G[v][i];
			if(cost[e.first][k+1]>cost[v][k]+e.second/2){
				cost[e.first][k+1]=cost[v][k]+e.second/2;
				que.push(PP(P(e.first,cost[e.first][k+1]),k+1));
			}
		}
	}

	int ans=INF;
	for(int i=0;i<=10;i++){
		ans=min(ans,cost[d][i]);
	}
	return ans;
}

int main(void){
	while(1){
		scanf("%d%d%d%d%d",&c,&n,&m,&s,&d);
		if(c==0 && n==0 && m==0 && s==0 && d==0)break;
		for(int i=0;i<=100;i++)G[i].clear();
		for(int i=0;i<m;i++){
			int a,b,f;
			scanf("%d%d%d",&a,&b,&f);
			G[a].push_back(P(b,f));
			G[b].push_back(P(a,f));
		}
		cout << dijkstra(s) << endl;
	}
    return 0;
}

C++: #include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
const ll INF = 114514810;
const ll MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int d[2000];
vector<vector<edge>> es;

void dijkstra(int s)
{
	fill(ALL(d), INF);
	d[s] = 0;
	priority_queue<P, vector<P>, greater<P>> que;
	que.push(P(0, s));
	while (!que.empty())
	{
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		REP(i, es[v].size())
		{
			edge e = es[v][i];
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main()
{
	int c, n, m, s, g;
	while (cin >> c >> n >> m >> s >> g, c)
	{
		s--; g--;
		es.clear();
		es.resize(c*n+n);
		REP(i, m)
		{
			int a, b, f;
			cin >> a >> b >> f;
			a--; b--;
			REP(j, c+1) es[a + j*n].push_back(edge{ a + j*n, b + j*n, f });
			REP(j, c) es[a + (j+1)*n].push_back(edge{ a + (j+1)*n, b + j*n, f/2 });
			REP(j, c + 1) es[b + j*n].push_back(edge{ b + j*n, a + j*n, f });
			REP(j, c) es[b + (j + 1)*n].push_back(edge{ b + (j + 1)*n, a + j*n, f / 2 });
		}
		dijkstra(s + c*n);
		int ans = INF;
		REP(i, c + 1) ans = min(ans, d[g + i*n]);
		cout << ans << endl;
	}

	return 0;
}

C++: #include <iostream>
#define INF 1000000000
using namespace std;


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

int ans[1000];
int counter=0;
bool flag=true;

void solve(){
	int d[101][11];//地点と割引回数
	edge route[500];//路線
	int c,n,m,s,t;//割引回数,町数,路線数,出発駅,到着駅
	cin >> c>>n>>m>>s>>t;
	if(c==0) {flag=false; return;}
	
	for(int i=0;i<m;i++){
		cin >>route[i].from>>route[i].to>>route[i].cost;
	}
	
	for(int i=1;i<=n;i++){
		for(int j=0;j<c+1;j++){//割引回数は割引無しも必要
			d[i][j]=INF;
		}
	}
	
	d[s][0]=0;
	bool update=true;
	while(update){
		update=false;
		for(int i=0;i<m;i++){
			edge e=route[i];//見やすく
			for(int j=0;j<=c;j++){
				//まずは割引無し
				if(d[e.from][j]!=INF && d[e.to][j]>d[e.from][j]+e.cost){
					d[e.to][j]=d[e.from][j]+e.cost; update=true;
				}
				if(d[e.to][j]!=INF && d[e.from][j]>d[e.to][j]+e.cost){
					d[e.from][j]=d[e.to][j]+e.cost; update=true;
				}
				
			}
			
			for(int j=0;j<c;j++){
				if(d[e.from][j]!=INF && d[e.to][j+1]>d[e.from][j]+e.cost/2){
					d[e.to][j+1]=d[e.from][j]+e.cost/2; update=true;
				}
				if(d[e.to][j]!=INF && d[e.from][j+1]>d[e.to][j]+e.cost/2){
					d[e.from][j+1]=d[e.to][j]+e.cost/2; update=true;
				}
			}
		}
	}
	
	ans[counter]=d[t][c];
	counter++;
}

int main(){
	while(flag){
		solve();
	}
	for(int i=0;i<counter;i++){
		cout << ans[i]<<endl;
	}
}