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]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 <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <numeric>
#include <limits>

using namespace std;

struct edge{ int to, cost; };
typedef pair<int, int> P;
const int INF = INT_MAX / 4;

int V;
vector<edge> G[100];
int D[100];
int pre[100];

int c, n, m, s, d;

void dijkstra(int s)
{
	priority_queue<P, vector<P>, greater<P> > que;
	fill(D, D + 100, INF);
	fill(pre, pre + 100, -1);
	D[s] = 0;
	que.push(P(0, s));

	while (!que.empty())
	{
		P p = que.top(); que.pop();
		int v = p.second;
		if (D[v] < p.first) continue;
		for (int i = 0; i < G[v].size(); i++)
		{
			edge e = G[v][i];
			if(D[e.to] > D[v] + e.cost)
			{
				D[e.to] = D[v] + e.cost;
				pre[e.to] = v;
				que.push(P(D[e.to], e.to));
			}
		}
	}
}

int solve()
{
	dijkstra(s - 1);
	vector<int> vec;
	for (int t = d - 1; pre[t] != -1 ; t = pre[t])
	{
		for (int i = 0; i < G[t].size(); i++)
		{
			if(pre[t] == G[t][i].to)
			{
				vec.push_back(G[t][i].cost);
				break;
			}
		}
	}
	sort(vec.begin(), vec.end(), greater<int>());
	for (int i = 0; i < c && i < vec.size(); i++)
	{
		vec[i] = vec[i] / 2;
	}
	return accumulate(vec.begin(), vec.end(), 0);
}

int main()
{
	while (cin >> c >> n >> m >> s >> d && c && n && m && s && d)
	{
		for (int i = 0; i < 100; i++)
		{
			G[i] = vector<edge>();
		}
		for (int i = 0; i < m; i++)
		{
			int a, b, f;
			cin >> a >> b >> f;
			edge e;
			e.to = b - 1;
			e.cost = f;
			G[a - 1].push_back(e);
			e.to = a - 1;
			e.cost = f;
			G[b - 1].push_back(e);
		}
		cout << solve() << endl;
	}
	return 0;
}

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

using namespace std;

const int INF = 10000000;

int city[101][101];

int solve( int s, int d, int c, int n ){
	int dist[11][101];
	int history[101];

	for( int i = 0;i < 11;i++ ){
		for( int j = 1;j < 101;j++ ){
			dist[i][j] = INF;
		}
	}

	for( int i = 1;i < 101;i++ ){
		history[i] = 0;
	}

	for( int i = 0;i < 11;i++ ) dist[i][s] = 0;

	typedef pair<int,int> data;
	typedef pair<int,data> graph;
	priority_queue<graph,vector<graph>,greater<graph> > q;

	q.push( graph( 0, data( s, c ) ) );

	while( !q.empty() ){
		graph a = q.top();
		int u = a.second.first;
		int uc = a.second.second;
		q.pop();
		history[u] = 1;

		for( int i = 1;i <= n;i++ ){

			if( dist[uc][i] > dist[uc][u] + city[u][i] ){
				dist[uc][i] = dist[uc][u] + city[u][i];
				q.push( graph( dist[uc][i], data( i, uc ) ) );
			}

			if( uc && dist[uc - 1][i] > dist[uc][i] + city[u][i] / 2 ){
				dist[uc - 1][i] = dist[uc][u] + city[u][i] / 2;
				q.push( graph( dist[uc - 1][i], data( i, uc - 1 ) ) );
			}
		}
	}
	int answer = INF;
	for( int i = 0;i < 11;i++ ) answer = min( dist[i][d], answer );
	return answer;

}

int main(int argc, char const* argv[])
{
	int c,n,m,s,d;

	while( cin >> c >> n >> m >> s >> d && c != 0 ){
		int a,b,f;
		for( int i = 1;i < 101;i++ ){
			for( int j = 1;j < 101;j++ ){
				city[i][j] = INF * 2;
			}
		}
		for( int i = 0;i < m;i++ ){
			cin >> a >> b >> f;
			city[a][b] = f;
			city[b][a] = f;
		}

		cout << solve( s, d, c, n ) << endl;
	}

	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<utility>
#include<queue>
#include<algorithm>
using namespace std;
#define INF 1000000000
int C,N,M,S,D,g1[101][101],s,t,c,d[11][101];
typedef struct P{int p,c,t;}P;
struct Order
{
	bool operator ()(P const& a, P const& b) const
	{
		return a.c>b.c;
	}
};

P tmp,tmp2;
priority_queue<P,vector<P>,Order>Q;
int main()
{
	for(;scanf("%d%d%d%d%d",&C,&N,&M,&S,&D),N;)
	{
		for(int i=0;i<=N;i++)
			for(int j=0;j<=N;j++)
				g1[i][j]=INF;
		for(int i=0;i<=C;i++)
			for(int j=0;j<=N;j++)
				d[i][j]=INF;
		for(int i=0;i<M;i++)
		{
			scanf("%d%d%d",&s,&t,&c);
			if(g1[s][t]>c)
				g1[s][t]=g1[t][s]=c;
		}
		d[C][S]=0;
		tmp.c=0;tmp.p=S;tmp.t=C;
		Q.push(tmp);
		for(;!Q.empty();)
		{
			tmp=Q.top(),Q.pop();
			for(int i=1;i<=N;i++)
			{
				int nc=tmp.c+g1[tmp.p][i];
				if(d[tmp.t][i]>nc)
				{
					tmp2.c=d[tmp.t][i]=nc;
					tmp2.p=i;
					tmp2.t=tmp.t;
					Q.push(tmp2);
				}
				nc=tmp.c+g1[tmp.p][i]/2;
				if(tmp.t>0&&d[tmp.t-1][i]>nc)
				{
					tmp2.c=d[tmp.t-1][i]=min(d[tmp.t][i],nc);
					tmp2.p=i;
					tmp2.t=tmp.t-1;
					Q.push(tmp2);
				}
			}
		}
		printf("%d\n",d[0][D]);
	}
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef pair<int, int>P;

struct node {
	int first, second, c;
};
bool operator<(node a, node b) {
	return a.second > b.second;
}
vector<P>E[100];
int d[100];

int main() {
	int c, n, m, s, g;
	while (scanf("%d%d%d%d%d", &c, &n, &m, &s, &g), c) {
		s--; g--;
		rep(i, 100)E[i].clear();
		memset(d, 0x3f, sizeof(d));
		rep(i, m) {
			int a, b, f; scanf("%d%d%d", &a, &b, &f);
			a--; b--;
			E[a].push_back(P(b, f)); E[b].push_back(P(a, f));
		}
		priority_queue<node>que;
		que.push({ s,0,c });
		d[s] = 0;
		while (!que.empty()) {
			node p = que.top(); que.pop();
			for (P i : E[p.first]) {
				if (p.c&& d[i.first] > p.second + i.second / 2) {
					d[i.first] = p.second + i.second / 2;
					que.push({ i.first, d[i.first],p.c - 1 });
				}
				if (d[i.first] > p.second + i.second) {
					d[i.first] = p.second + i.second;
					que.push({ i.first, d[i.first],p.c });
				}
			}
		}
		printf("%d\n", d[g]);
	}
}