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]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;

#define llong long long 
typedef pair<int, int> P;

typedef struct data{
	int now;
	int time;
	int dep;

	bool operator > (const data& right) const{
		return dep == right.dep ? time > right.time : dep > right.dep;
	}

}data;

int c, n, m, s, d;
vector<P> edges[101];
int cost[101][11];
priority_queue<data, vector<data>, greater<data> > q;

void solve(){
	data D;
	D.now = s;
	D.time = 0;
	D.dep = 0;
	q.push(D);

	while(!q.empty()){
		data nd = q.top(); q.pop();
		int nowp = nd.now;
		int nowtime = nd.time;
		int nowdep = nd.dep;

		if(cost[nowp][nowdep] < nowtime) continue;

		for(int i = 0; i < edges[nowp].size(); i++){
			P edge = edges[nowp][i];
			if(cost[edge.first][nowdep] > cost[nowp][nowdep] + edge.second){
				data in;
				in.now = edge.first;
				in.time = cost[nowp][nowdep] + edge.second;
				in.dep = nd.dep;
				cost[in.now][in.dep] = in.time;
				q.push(in);
			}

			if(nowdep < c){
				if(cost[edge.first][nowdep + 1] > cost[nowp][nowdep] + edge.second / 2){
					data in;
					in.now = edge.first;
					in.time = nowtime + (edge.second / 2);
					in.dep = nowdep + 1;
					cost[in.now][in.dep] = in.time;
					q.push(in);
				}			
			}

		}
	}

	return;
}

int main(){
	while(cin >> c >> n >> m >> s >> d, n){
		fill_n(*cost, 101 * 11, 99999999);
		for(int i = 0; i <= c; i++){
			cost[s][i] = 0;
		}
		for(int i = 0; i < m; i++){
			int n, to, cos;
			cin >> n >> to >> cos;
			edges[n].push_back(P(to, cos));
			edges[to].push_back(P(n, cos));
		}

		solve();

		// cout << cost[d][c] << endl;
		int minc = 999999999;
		for(int i = 0; i <= c; i++)
			minc = min(minc, cost[d][i]);
		cout << minc << endl;
		for(int i = 0; i < 101; i++){
			edges[i].clear();
		}
	}

	return 0;
}

C++: #include <map>
#include <vector>
#include <cstdio>
#include <cstring>
using namespace std;
int cost[101][11];
int main(){
	int c,N,m,s,d,i,j,k,x;
	for(;scanf("%d%d%d%d%d",&c,&N,&m,&s,&d),N;){
	fprintf(stderr,"%d %d %d %d %d\n",c,N,m,s,d);
		vector<map<int,int> >dist(N+1);
		memset(cost,99,sizeof(cost));
		for(k=0;k<m;k++){
			scanf("%d%d%d",&i,&j,&x);dist[i][j]=dist[j][i]=x;
			fprintf(stderr,"%d %d %d\n",i,j,x);
		}
		for(i=0;i<=c;i++)cost[s][i]=0;
		for(;~c;c--){
			vector<bool>used(N+1);
			for(;;){ //dijkstra
				int m=9999999;
				for(i=0;i<N;i++)if(!used[i]&&m>cost[i][c])m=cost[i][c];
				if(m==9999999)break;
				for(j=0;j<N;j++)if(m==cost[j][c]){
					map<int,int>::iterator it=dist[j].begin();
					for(used[j]=1;it!=dist[j].end();it++){
						if(cost[it->first][c]>it->second+cost[j][c])cost[it->first][c]=it->second+cost[j][c];
						if(c&&cost[it->first][c-1]>it->second/2+cost[j][c])cost[it->first][c-1]=it->second/2+cost[j][c];
					}
				}
			}
		}
		printf("%d\n",cost[d][0]);
	}
}

C++: #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
using namespace std;

const int INF=10000000;
typedef struct edge{
  int t,c;
  edge(){}
  edge(int t,int c):t(t),c(c){}
};
typedef pair<int ,pair<int,int> > P;


vector<edge> g[105];
int id[11][105];
int c,n,m,s,d;

int main(void){
  while(1){
    scanf("%d %d %d %d %d",&c,&n,&m,&s,&d);
    if(!c && !n && !m && !s && !d) break;
    for(int i=0;i<=n;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(edge(b,f));
      g[b].push_back(edge(a,f));
    }

    priority_queue<P,vector<P>,greater<P> > que;
    for(int i=0;i<=c;i++) fill(id[i],id[i]+n+1,INF);
    for(int i=0;i<10;i++)id[i][s]=0;
    que.push(P(0,pair<int,int>(s,c)));
    while(!que.empty()){
      P p=que.top();
      que.pop();
      int v=p.second.first;
      int nc=p.second.second;
      if(v == d) {
	printf("%d\n",id[c-nc][v]);
	break;
      }
      if(id[c-nc][v]<p.first) continue;
      for(int i=0;i<g[v].size();i++){
	edge e = g[v][i];
	if(id[c-nc][e.t]>id[c-nc][v]+e.c){
	  id[c-nc][e.t]=id[c-nc][v]+e.c;
	  que.push(P(id[c-nc][e.t],pair<int,int>(e.t,nc)));
	}
	if(nc>0 && id[c-nc+1][e.t]>id[c-nc][v]+e.c/2){
	  id[c-nc+1][e.t]=id[c-nc][v]+e.c/2;
	  que.push(P(id[c-nc+1][e.t],pair<int,int>(e.t,nc-1)));
	}
      }
    }
    /*
    for(int i=1;i<=n;i++) printf("%d:%d  ",i,id[c][i]);
    puts("");
    printf("%d\n",id[c][d]);
    */
  }
}