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
}

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)
		for len(pq) != 0 {
			now := heap.Pop(&pq).(*Node)
			if now.NowPosition == d {
				fmt.Println(now.Amount)
				break
			}
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				heap.Push(&pq, next)
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					heap.Push(&pq, next)
				}
			}
		}
	}
}

C++: //1.includes
#include<iostream>
#include<algorithm>
#include<queue>
#include<tuple>
#include<functional>
#include<vector>
using namespace std;

//2.defines
#define INF 1000000000000000000LL//10^18
#define MAX_N 1000
#define MAX_C 100
#define BLACK 2
#define GRAY 1
#define WHITE 0

//3.variables
priority_queue<tuple<long long, long long, long long>, vector<tuple<long long, long long, long long>>, greater<tuple<long long, long long, long long>>>Q;
long long dist[MAX_N][MAX_C];
long long color[MAX_N][MAX_C];
vector<pair<long long, long long>>X[MAX_N];
long long C, N, M, S, D, A, B, G;

//4.functions
void _memset() {
	for (int i = 0; i < MAX_N; i++) {
		for (int j = 0; j < MAX_C; j++) {
			dist[i][j] = 0;
			color[i][j] = WHITE;
		}
	}
	for (int i = 0; i < MAX_N; i++) {
		X[i].clear();
	}
	while (!Q.empty()) {
		Q.pop();
	}
}

long long dijkstra(long long s, long long t, long long u) {
	for (int i = 0; i < MAX_N; i++) {
		for (int j = 0; j < MAX_C; j++) {
			dist[i][j] = INF;
			color[i][j] = WHITE;
		}
	}
	Q.push(make_tuple(0, 0, s));
	dist[s][0] = 0;
	color[s][0] = GRAY;
	while (!Q.empty()) {
		tuple<long long, long long, long long> tup = Q.top();
		Q.pop();
		long long a1 = get<0>(tup);
		long long a2 = get<1>(tup);
		long long a3 = get<2>(tup);
		color[a3][a2] = BLACK;
		for (int i = 0; i < X[a3].size(); i++) {
			long long a4 = X[a3][i].first;
			long long a5 = X[a3][i].second;
			bool ok = true;
			if (color[a4][a2] == BLACK) { ok = false; }
			if (ok == true && a1 + a5 < dist[a4][a2]) {
				dist[a4][a2] = a1 + a5;
				color[a4][a2] = GRAY;
				Q.push(make_tuple(dist[a4][a2], a2, a4));
			}
			ok = true;
			if (color[a4][a2 + 1] == BLACK) { ok = false; }
			if (a2 + 1 > u) { ok = false; }
			if (ok == true && a1 + a5 / 2 < dist[a4][a2 + 1]) {
				dist[a4][a2 + 1] = a1 + a5 / 2;
				color[a4][a2 + 1] = GRAY;
				Q.push(make_tuple(dist[a4][a2 + 1], a2 + 1, a4));
			}
		}
	}
	long long minx = INF;
	for (int i = 0; i <= u; i++) {
		minx = min(minx, dist[t][i]);
	}
	return minx;
}

int main() {
	while (true) {
		_memset();
		cin >> C >> N >> M >> S >> D;
		if (C == 0 && N == 0 && M == 0 && S == 0 && D == 0) {
			break; //C=number of ticket
		}
		for (int i = 0; i < M; i++) {
			cin >> A >> B >> G;
			X[A].push_back(make_pair(B, G));
			X[B].push_back(make_pair(A, G));
		}
		cout << dijkstra(S, D, C) << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<queue>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int c,n,m,s,d; while(cin>>c>>n>>m>>s>>d,c){
		s--,d--;
		int a,b,f;
		int ad[n][n],cost[c+1][n];
		rep(i,n)rep(j,n)ad[i][j]=0;
		rep(i,c+1)rep(j,n)cost[i][j]=1<<20;
		rep(i,m)cin>>a>>b>>f,a--,b--,ad[a][b]=ad[b][a]=f;
		queue<pair<int,int> > F; F.push(make_pair(s,c));
		cost[c][s]=0;
		while(!F.empty()){
			int cnode=F.front().first,cc=F.front().second; F.pop();
			rep(i,n)if(ad[cnode][i]){
				if(cost[cc][i]>cost[cc][cnode]+ad[cnode][i])
				cost[cc][i]=cost[cc][cnode]+ad[cnode][i],
				F.push(make_pair(i,cc));
				if(cc>0&&cost[cc-1][i]>cost[cc][cnode]+ad[cnode][i]/2)
				cost[cc-1][i]=cost[cc][cnode]+ad[cnode][i]/2,
				F.push(make_pair(i,cc-1));
			}
		}
		int mi;rep(i,c+1)if(cost[i][d]!=1<<20){mi=i;break;}
		cout<<cost[mi][d]<<endl;
	}
	return 0;
}

C++: // 2010/12/29 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int c, n, m, s, d;
		cin >> c >> n >> m >> s >> d;
		if(c==0&&n==0&&m==0&&s==0&&d==0)
			break;

		int wgt[102][102];
		int hlf[102][102];
		for(int i=1; i<=n; i++)
			for(int j=1; j<=n; j++)
				if(i==j){
					wgt[i][j] = 0;
					hlf[i][j] = 20000;
				}
				else{
					wgt[i][j] = 20000;
					hlf[i][j] = 20000;
				}

		for(int i=0; i<m; i++){
			int a, b, f;
			cin >> a >> b >> f;
			wgt[a][b] = f;
			wgt[b][a] = f;
			hlf[a][b] = f/2;
			hlf[b][a] = f/2;
		}

		int djk[12][102];
		bool flg[12][102];
		for(int j=c; j>=0; j--)
			for(int i=1; i<=n; i++){
				djk[j][i] = 2000000;
				flg[j][i] = false;
			}
		djk[c][s] = 0;

		while(true){
			int j_min;
			int i_min;
			int w_min = 2000000;
			for(int j=0; j<=c; j++)
				for(int i=1; i<=n; i++)
					if((!flg[j][i])&&(djk[j][i]<w_min)){
						j_min = j;
						i_min = i;
						w_min = djk[j][i];
					}

			flg[j_min][i_min] = true;
			if(i_min==d){
				cout << djk[j_min][i_min] << endl;
				break;
			}

			for(int i=1; i<=n; i++)
				if(!flg[j_min][i])
					if(wgt[i_min][i]!=20000)
						if(djk[j_min][i]>djk[j_min][i_min]+wgt[i_min][i])
							djk[j_min][i] = djk[j_min][i_min]+wgt[i_min][i];
			if(j_min!=0)
				for(int i=1; i<=n; i++)
					if(!flg[j_min-1][i])
						if(hlf[i_min][i]!=20000)
							if(djk[j_min-1][i]>djk[j_min][i_min]+hlf[i_min][i])
								djk[j_min-1][i] = djk[j_min][i_min]+hlf[i_min][i];
		}
	}

	return 0;
}