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 <cstdio>
#include <utility>
#include <queue>
#include <algorithm>
#define INF (1<<27)
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int> _P; //point chicket
typedef pair<int,_P> P; //cost _P
struct Edge {
	int to,cost;
	Edge(int _to,int _cost) {to=_to,cost=_cost;}
};
int dist[11][100];
vector<Edge> edges[100];
int main() {
	int c,n,m,s,d;
	while(scanf("%d %d %d %d %d",&c,&n,&m,&s,&d),c) {
		rep(i,n) edges[i].clear();
		rep(i,c+1) rep(j,n) dist[i][j]=INF;
		rep(i,m) {
			int a,b,f;
			scanf("%d %d %d",&a,&b,&f);
			edges[a-1].push_back(Edge(b-1,f));
			edges[b-1].push_back(Edge(a-1,f));
		}
		priority_queue<P,vector<P>,greater<P> > Q;
		Q.push(P(0,_P(s-1,c)));
		dist[c][s-1]=0;
		while(!Q.empty()) {
			P p=Q.top(); Q.pop();
			_P _p=p.second;
			if(dist[_p.second][_p.first]<p.first) continue;
			rep(i,edges[_p.first].size()) {
				if(dist[_p.second][edges[_p.first][i].to]>(p.first+edges[_p.first][i].cost)) {
					dist[_p.second][edges[_p.first][i].to]=(p.first+edges[_p.first][i].cost);
					Q.push(P(p.first+edges[_p.first][i].cost,_P(edges[_p.first][i].to,_p.second)));
				}
				if(_p.second>0&&(dist[_p.second-1][edges[_p.first][i].to]>(p.first+edges[_p.first][i].cost/2))) {
					dist[_p.second-1][edges[_p.first][i].to]=(p.first+edges[_p.first][i].cost/2);
					Q.push(P(p.first+edges[_p.first][i].cost/2,_P(edges[_p.first][i].to,_p.second-1)));
				}
			}
		}
		int sum=1<<30;
		rep(i,c+1)if(sum>dist[i][d-1])sum=dist[i][d-1];
		printf("%d\n",sum);
	}
}

C++: #include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
};

/** Problem0212 : Highway Express Bus **/
struct edge{
	int from, to, cost;
	edge(int f, int t, int c):from(f), to(t), cost(c){}
	edge(){}
};
vector<edge> G;

int main()
{
	int C, N, M, S, D;
	while (cin>>C>>N>>M>>S>>D, C) {
		S--, D--;
		G.clear();
		
		rep(i, M) {
			int a, b, f;
			cin>>a>>b>>f;
			a--, b--;
			G.push_back(edge(a, b, f));
			G.push_back(edge(b, a, f));
		}
		
		int d[100][11];
		fill(d[0], d[0]+100*11, INF);
		for (int i=0; i<=C; i++) d[S][i]=0;
		
		while (true) {
			bool update=false;
			
			for (int i=0; i<G.size(); i++) {
				edge e = G[i];
				for (int j=0; j<=C; j++) {
					if (d[e.to][j] > d[e.from][j] + e.cost) {
						d[e.to][j] = d[e.from][j] + e.cost;
						update = true;
					}
					
					
					if (j+1<=C) {
						if (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 (!update) break;
		}
		
		int ans = INF;
		for (int i=0; i<=C; i++) {
			ans = min(ans, d[D][i]);
		}
		cout << ans << endl;
	}
}