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]int)
		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}] = now.Amount
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				if memoAmount, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok || (ok && memoAmount > next.Amount) {
					memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}] = next.Amount
					heap.Push(&pq, next)
				}
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					if memoAmount, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok || (ok && memoAmount > next.Amount) {
						memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}] = next.Amount
						heap.Push(&pq, next)
					}
				}
			}
		}
		//runtime.GC()
	}
}

C++: #include <iostream>
#include <queue>

#define INF 1e9

using namespace std;

struct Edge {
	int to, cost;
};
struct Node {
	int now, rest, cost;
};
bool operator <(const Node& n1, const Node& n2) {
	return n1.cost < n2.cost;
}

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

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

		int ans[100][11]; fill(&ans[0][0], &ans[0][0]+100*11, INF);
		priority_queue<Node> Q; Q.push( (Node){s, c, 0} );
		while ( !Q.empty() ) {
			Node node = Q.top(); Q.pop();
			if (node.cost >= ans[node.now][node.rest]) continue;
			ans[node.now][node.rest] = node.cost;

			for (int i = 0; i < m[node.now].size(); ++i) {
				Edge& e = m[node.now][i];
				if (node.cost+e.cost < ans[e.to][node.rest]) {
					Q.push( (Node){ e.to, node.rest, node.cost+e.cost } );
				}

				if (node.rest > 0) {
					if (node.cost+e.cost/2 < ans[e.to][node.rest-1]) {
						Q.push( (Node){ e.to, node.rest-1, node.cost+e.cost/2 } );
					}
				}
			}
		}
		int a = INF;
		for (int i = 0; i <= c; ++i) a = min(a, ans[d][i]);
		cout << a << endl;
	}
}

C++: #include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#define INF 10e6 
using namespace std;

int c,n,m,s,d;

int cost[101][101];
bool state[101][11];
struct node{
	int c;  //cost
	int n;	//number
	int t;	//times
	bool operator >(node b)const{
    return c > b.c;
	}
};




int dijkstra(int s,int g){
	node start;
	start.c=0,start.n=s,start.t=c;
	priority_queue<node,vector<node>,greater<node> > q;
	q.push(start);
	while(!q.empty()){
		node cur=q.top();
		q.pop();
		if(cur.n == g){
			int ans=cur.c;
			return ans;
		}
		if(state[cur.n][cur.t])
			continue;
		else
			state[cur.n][cur.t]=true;; 
		for(int i=1;i<=n;i++){
			if(cur.n== i)
				continue;
			node next;
			if(cur.t > 0){
				next.c=cur.c+(cost[cur.n][i]/2);
				next.n=i;
				next.t=cur.t-1;
				q.push(next);
			}
			next.c=cur.c+cost[cur.n][i];
			next.n=i;
			next.t=cur.t;
			q.push(next);
		}
	} 
	return INF;
}
int main(void){
	while(cin >> c >> n >> m >> s >> d,c|n|m|s|d){
		for(int i=1;i<=n;i++)
			for(int j=1;j<=c;j++)
				state[i][j]=false;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				cost[i][j]=INF;
		int a,b,f;
		for(int i=0;i<m;i++){
			cin >> a >> b >> f;
			cost[a][b]=cost[b][a]=f;
		}
		int ans=dijkstra(s,d);
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#define INF 10e6 
using namespace std;

int c,n,m,s,d;

int cost[101][101];

struct node{
	int c;  //cost
	int n;	//number
	int t;	//times
	bool operator >(node b)const{
    return c > b.c;
	}
};




int dijkstra(int s,int g){
	node start;
	start.c=0,start.n=s,start.t=c;
	priority_queue<node,vector<node>,greater<node> > q;
	q.push(start);
	while(!q.empty()){
		node cur=q.top();
		q.pop();
		if(cur.n == g){
			int ans=cur.c;
			return ans;
		}
		for(int i=1;i<=n;i++){
			if(cur.n== i)
				continue;
			node next;
			if(cur.t > 0){
				next.c=cur.c+(cost[cur.n][i]/2);
				next.n=i;
				next.t=cur.t-1;
				q.push(next);
			}
			next.c=cur.c+cost[cur.n][i];
			next.n=i;
			next.t=cur.t;
			q.push(next);
		}
	} 
	return INF;
}
int main(void){
	while(cin >> c >> n >> m >> s >> d,c|n|m|s|d){
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				cost[i][j]=INF;
		int a,b,f;
		for(int i=0;i<m;i++){
			cin >> a >> b >> f;
			cost[a][b]=cost[b][a]=f;
		}
		int ans=dijkstra(s,d);
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <queue>

#define INF 1e9

using namespace std;

struct Edge {
	int to, cost;
};
struct Node {
	int now, rest, cost;
};
bool operator <(const Node& n1, const Node& n2) {
	return n1.cost < n2.cost;
}

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

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

		int ans[100][11]; fill(&ans[0][0], &ans[0][0]+100*11, INF);
		priority_queue<Node> Q; Q.push( (Node){s, c, 0} );
		while ( !Q.empty() ) {
			Node node = Q.top(); Q.pop();
			if (node.cost >= ans[node.now][node.rest]) continue;
			ans[node.now][node.rest] = node.cost;

			for (int i = 0; i < m[node.now].size(); ++i) {
				Edge& e = m[node.now][i];
				if (node.cost+e.cost < ans[e.to][node.rest]) {
					Q.push( (Node){ e.to, node.rest, node.cost+e.cost } );
				}

				if (node.rest > 0) {
					if (node.cost+e.cost/2 < ans[e.to][node.rest-1]) {
						Q.push( (Node){ e.to, node.rest-1, node.cost+e.cost/2 } );
					}
				}
			}
		}
		int a = INF;
		for (int i = 0; i <= c; ++i) a = min(a, ans[d][i]);
		cout << a << endl;
	}
}