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 <iostream>
#include <vector>
#include <queue>

using namespace std;

struct node {
	int to, cost, ticket;

	node(int to, int cost) : to(to), cost(cost) { this -> ticket = 0; }
	node(int to, int cost, int ticket) : to(to), cost(cost), ticket(ticket) { }
	node() { this -> to = this -> cost = this -> ticket = 0; }
};

bool operator < (const node &a, const node &b) {
	return a.cost < b.cost;
}

bool operator > (const node &a, const node &b) {
	return a.cost > b.cost;
}

int main() {
	int c, n, m, s, d;
	while (cin >> c >> n >> m >> s >> d, c || n || m || s || d) {
		--s, --d;

		vector< vector<node> > v(n);
		for (int i = 0; i < m; ++i) {
			int a, b, f; cin >> a >> b >> f;
			--a, --b;
			v[a].push_back( node(b, f) );
			v[b].push_back( node(a, f) );
		}

		vector< vector<int> > cost(n, vector<int>(c+1, -1));
		vector<bool> used(n, -1);
		priority_queue< node, vector<node>, greater<node> > que; que.push( node(s, 0, c) );
		while ( !que.empty() ) {
			node next = que.top(); que.pop();

			if (cost[next.to][next.ticket] >= 0) continue;

			cost[next.to][next.ticket] = next.cost;

			for (int i = 0; i < v[next.to].size(); ++i) {
				que.push( node(v[next.to][i].to, next.cost + v[next.to][i].cost, next.ticket) );
				if (next.ticket) que.push( node(v[next.to][i].to, next.cost + v[next.to][i].cost/2, next.ticket-1) );
			}
		}

		cout << cost[d][0] << endl;
	}
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
double EPS=1e-10;
int INF=1e9;
static const int MEM_SIZE=1000000;
struct edge{int to,cost;};
struct dat{
      int s,cost,num;
      dat(int s,int cost,int num):s(s),cost(cost),num(num){}
      bool operator<(const dat& a)const{return cost<a.cost;}
};
vector<edge> G[100];
int dist[100][11];
int n,c;
void dijkstra(int s){
      REP(i,100)REP(j,11)dist[i][j]=INF;
      priority_queue<dat>Q;
      Q.push(dat(s,0,0));
      dist[s][0]=0;
      while(!Q.empty()){
            dat p=Q.top();Q.pop();
            if(p.cost>dist[p.s][p.num])continue;
            REP(i,G[p.s].size()){
                  edge e=G[p.s][i];
                  if(p.num<c){
                        if(dist[p.s][p.num]+e.cost/2<dist[e.to][p.num+1]){
                              dist[e.to][p.num+1]=dist[p.s][p.num]+e.cost/2;
                              Q.push(dat(e.to,dist[e.to][p.num+1],p.num+1));
                        }
                  }
                  if(dist[p.s][p.num]+e.cost<dist[e.to][p.num]){
                        dist[e.to][p.num]=dist[p.s][p.num]+e.cost;
                        Q.push(dat(e.to,dist[e.to][p.num],p.num));
                  }
            }
      }
}
int main(){
      int m,s,d;
      while(cin>>c>>n>>m>>s>>d&&(c||n||m||s||d)){
            s--;d--;
            REP(i,100)G[i].clear();
            REP(i,m){
                  int a,b,f;
                  cin>>a>>b>>f;
                  a--;b--;
                  G[a].PB((edge){b,f});
                  G[b].PB((edge){a,f});
            }
            dijkstra(s);
            int ans=INF;
            /*REP(i,n){
                  REP(j,c+1){
                        cout<<dist[i][j];
                        if(j==c-1)cout<<endl;
                        else cout<<" ";
                        //cout<<i<<" "<<j<<endl;
                  }
            }*/
            REP(i,c+1)ans=min(ans,dist[d][i]);
            cout<<ans<<endl;
      }
}

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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<28

using namespace std;
typedef pair<int,int> P;


struct edge
{
	int to;
	int cost;

	edge(int to,int cost) : to(to),cost(cost) {}
};

int d[10][100];
vector<edge> G[100];

void dijkstra(int s,int n,int ticket)
{
	priority_queue<P,vector<P>,greater<P> > que;
	rep(i,n) d[i][ticket] = INF;
	d[s][ticket] = 0;
	que.push(P(0,s));

	while(!que.empty())
	{
		P p = que.top();
		que.pop();

		int v = p.second;
		if(d[v][ticket] < p.first) continue;

		rep(i,G[v].size())
		{
			edge e = G[v][i];
			int temp;

			if(ticket == 0)
			{
				temp = d[v][ticket] + e.cost;
			}
			else
			{
				temp =  min(d[v][ticket]+e.cost,d[v][ticket-1]+e.cost/2);
			}

			if(d[e.to][ticket] > temp)
			{
				d[e.to][ticket] = temp;
				que.push(P(d[e.to][ticket],e.to));
			}
		}
	}
}

int main()
{
	int c,n,m,s,t;
	while(cin >> c >> n >> m >> s >> t)
	{
		if(c == 0 && n == 0 && m == 0 && s == 0 && t == 0) break;
		
		s--;
		t--;
		rep(i,100) G[i].clear();

		rep(i,m)
		{
			int a,b,cost;
			cin >> a >> b >> cost;
			a--;
			b--;

			edge e(b,cost);
			G[a].push_back(e);

			edge e2(a,cost);
			G[b].push_back(e2);
		}
		
		rep(i,n) dijkstra(s,n,i);

		cout <<  d[t][c] << endl;
	}

	return 0;
}