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 <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int c,n,m,s,d;

int main(){
    while(true){
	scanf("%d%d%d%d%d",&c,&n,&m,&s,&d);
	if(c==0||n==0||m==0||s==0||d==0) break;
	int rosen[101][101] = {10000000};
	int dp[11][101];
	REP(i,101)REP(j,101) rosen[i][j] = 10000000;
	REP(i,11)REP(j,101) dp[i][j] = 10000000;
	REP(i,m){
	    int a,b,f;
	    cin >> a >> b >> f;
	    rosen[a][b] = f;
	    rosen[b][a] = f;
	}
	int ans = 10000000;
	vector<bool>  used(n+1,false);
	queue<int> q;
	queue<int> th;
	dp[c][s] = 0;
	q.push(s);
	th.push(c);
	while(!q.empty()){
	    int p = q.front();
	    int t = th.front();
	    q.pop();
	    th.pop();
	    FOR(i,1,n+1){
		if(dp[c][i] > dp[c][p] + rosen[p][i]){
		    dp[c][i] = dp[c][p] + rosen[p][i];
		    q.push(i);
		    th.push(t);
		}
		if(t>0&&dp[t-1][i] > dp[t][p] + rosen[p][i]/2){
		    dp[t-1][i] = dp[t][p] + rosen[p][i]/2;
		    q.push(i);
		    th.push(t-1);
		}
	    }
	}
	REP(i,c+1){
	    if(dp[i][d] > 0)
		ans = min(ans,dp[i][d]);
	}
	cout << ans << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
using namespace std;

#define INF 100000000

struct edge {
	int to;
	int f;
	edge(int to_, int f_) {
		to = to_; f = f_;
	}
	edge(){}
};
struct status {
	int vertex;
	int cost;
	int c;
	status(int vertex_, int cost_, int c_) {
		vertex = vertex_; cost = cost_; c = c_;
	}
	status(){}
	bool operator<(const status & obj) const {
		return this->cost > obj.cost;
	}
};

int main() {
	while(true) {
		int c, n, m, s, d;
		cin >> c >> n >> m >> s >> d;
		if(!(c || n || m || s || d))
			break;
		s--; d--;
		vector<vector<edge> > v(n);
		for(int i = 0; i < m; i++) {
			int a, b, f;
			cin >> a >> b >> f;
			a--; b--;
			v[a].push_back(edge(b,f));
			v[b].push_back(edge(a,f));
		}
		priority_queue<status> q;
		int cost[128][16];
		for(int i = 0; i < 128; i++)
			for(int j = 0; j < 16; j++)
				cost[i][j] = INF;
		q.push(status(s, 0, c));
		while(!q.empty()) {
			status cur;
			cur = q.top(); q.pop();

			if(cost[cur.vertex][cur.c] == INF) {
				cost[cur.vertex][cur.c] = cur.cost;
				for(int i = 0; i < v[cur.vertex].size(); i++) {
					if(cost[v[cur.vertex][i].to][cur.c] == INF) {
						q.push(status(v[cur.vertex][i].to, v[cur.vertex][i].f + cur.cost, cur.c));
					}
					if(cur.c > 0 && cost[v[cur.vertex][i].to][cur.c-1] == INF) {
						q.push(status(v[cur.vertex][i].to, v[cur.vertex][i].f / 2 + cur.cost, cur.c - 1));
					}
				}
			}
		}

		int ret = INF;
		for(int i = 0; i < m; i++) {
			ret = min(ret, cost[d][i]);
		}
		cout << ret << endl;
	}
}

C++: /*
g£_CNXg
*/
#include<iostream>
#include<queue>
#include<map>
#define INF 10000000
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int> p;
typedef pair<int,p> P;
//P(cost,p(node,ticket))
struct edge{
	int cost,to;
};
int nticket,nnode,nedge,start,goal,d[11][101];
vector<edge> v[101];
void dijkstra(){
	int nowticket,nowplace,nowsum;
	priority_queue<P,vector<P>,greater<P> > que;
	que.push(P(0,p(start,nticket)));
	while(!que.empty()){
		P now=que.top();
		que.pop();
		
		nowsum=now.first;
		nowplace=now.second.first;
		nowticket=now.second.second;
		
		if(d[nowticket][nowplace]<nowsum)
			continue;
		rep(i,(int)v[nowplace].size()){
			edge e=v[nowplace][i];
			if(nowticket>0){
				if(d[nowticket-1][e.to]>e.cost/2+nowsum){
				d[nowticket-1][e.to]=e.cost/2+nowsum;
				que.push(P(d[nowticket-1][e.to],p(e.to,nowticket-1)));
				}
			}
			if(d[nowticket][e.to]>e.cost+nowsum){
				d[nowticket][e.to]=e.cost+nowsum;
				que.push(P(d[nowticket][e.to],p(e.to,nowticket)));
			}
		}
	}
}
void input(){
	int a,b,f;
	rep(i,nedge){
			cin>>a>>b>>f;
			a--;b--;
			edge c;
			c.cost=f;
			c.to=b;v[a].push_back(c);
			c.to=a;v[b].push_back(c);
		}
}
void init(){
	rep(i,nticket+1)
		rep(j,nnode){
			if(j==start)
			d[i][j]=0;
			else
			d[i][j]=INF;
	}
}
int main(){
	//d[ticket][node]=Å­ïp
	while(cin>>nticket>>nnode>>nedge>>start>>goal,nticket||nnode||nedge||start||goal){
		start--;goal--;
		//ticket:`Pbg
		//nnode:nodeÌ
		//nedge:edgeÌ
		//start¨goal
		input();
		init();
		dijkstra();
		int ans=INF;
		for(int i=0;i<nticket+1;i++)
		ans=min(d[i][goal],ans);
		cout<<ans<<endl;
		for(int i=0;i<nnode;i++)
		v[i].clear();
	}
	return 0;
}