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 <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ALL(A)		(A).begin(),(A).end()
#define DUMP(A)    cout<<#A<<"="<<(A)<< endl
#define SIZE(A)    (int)((A).size())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

int main(){
    int c,n,m,s,d;
    for(;;){
        scanf("%d%d%d%d%d",&c,&n,&m,&s,&d);
        if(c==0&&n==0&&m==0&&s==0&&d==0) break;
        s--;d--;
        int path[100][100];
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                path[i][j]=-1;
            }
        }
        int fr,to,co;
        for(int i=0;i<m;i++){
            scanf("%d%d%d",&fr,&to,&co);
            fr--;to--;
            path[fr][to]=path[to][fr]=co;
        }
        int dist[100][11];
        for(int i=0;i<n;i++){
            for(int j=0;j<=c;j++){
                dist[i][j]=-1;
            }
        }
        priority_queue<PP,vector<PP>,greater<PP> > pque;
        pque.push(PP(0,P(0,s)));
        dist[s][0]=0;
        while(!pque.empty()){
            PP now=pque.top();
            pque.pop();
            int ndi=now.first,ncar=now.second.first,nat=now.second.second;
            if(dist[nat][ncar]!=-1 && dist[nat][ncar]<ndi) continue;
            for(int i=0;i<n;i++){
                if(path[nat][i]!=-1 && (dist[i][ncar]==-1 || ndi+path[nat][i]<dist[i][ncar])){
                    pque.push(PP(ndi+path[nat][i],P(ncar,i)));
                    dist[i][ncar]=ndi+path[nat][i];
                }
                if(path[nat][i]!=-1 && ncar+1<=c && (dist[i][ncar+1]==-1 || ndi+path[nat][i]/2 < dist[i][ncar+1])){
                    pque.push(PP(ndi+path[nat][i]/2,P(ncar+1,i)));
                    dist[i][ncar+1]=ndi+path[nat][i]/2;
                }
            }
        }
        int mi=INT_MAX;
        for(int i=0;i<=c;i++){
            if(dist[d][i]!=-1 && dist[d][i]<mi) mi=dist[d][i];
        }
        printf("%d\n",mi);
    }
}

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

int C, N, M, S, D; //??????????????°???????????°???????????°???????????°???????????°
int cost[101];
int INF = 999999999;

class Edge
{
public:
	int to, cost;
	Edge(int to, int cost) : to(to), cost(cost){}
};

class Vertax
{
public:
	int n;
	int cost;
	priority_queue<int, vector<int>, greater<int>> discount;
	Vertax(){}

	Vertax get(Edge e)
	{
		Vertax v = *this;
		if (discount.size() == C)
		{
			v.cost += e.cost / 2;
			v.discount.push(e.cost);
			v.cost += discount.top() / 2;
			v.discount.pop();
		}
		else
		{
			v.cost += e.cost / 2;
			v.discount.push(e.cost);
		}
		v.n = e.to;
		return v;
	}
};

bool operator > (Vertax v1, Vertax v2)
{
	return (v1.cost > v2.cost);
}
bool operator < (Vertax v1, Vertax v2)
{
	return (v1.cost < v2.cost);
}

priority_queue<Vertax, vector<Vertax>, greater<Vertax>> que;

int main()
{
	while (cin >> C >> N >> M >> S >> D, C + N + M + S + D)
	{
		fill(cost + 1, cost + N + 1, INF);
		vector<Edge> e[501];

		for (int i = 0; i < M; i++)
		{
			int from, to, cost;
			cin >> from >> to >> cost;
			e[from].push_back(Edge(to, cost));
			e[to].push_back(Edge(from, cost));
		}

		Vertax start;
		start.n = S;
		start.cost = 0;
		que.push(start);
		cost[S] = 0;

		while (!que.empty())
		{
			Vertax v = que.top();
			que.pop();

			for (int i = 0; i < e[v.n].size(); i++)
			{
				Edge edge = e[v.n][i];
				Vertax next = v.get(edge);
				if (cost[next.n] > next.cost)
				{
					cost[next.n] = next.cost;
					que.push(next);
				}
			}
		}

		cout << cost[D] << endl;
	}

	return 0;
}

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

constexpr int MAX_N = 100, INF = (int)1e9;
using P = std::pair<std::pair<int, int>,int>;

struct edge {
	int to_, cost_;
	edge() = default;
	edge(int to, int cost) : to_(to), cost_(cost) {}
};

int c, n;
std::vector<edge> G[MAX_N];
int d[MAX_N];

int dijkstra(int s, int g) {
	std::fill(d, d + n, INF);
	std::priority_queue<P, std::vector<P>, std::greater<P>> que;
	d[s] = 0;
	que.emplace(std::make_pair(d[s], s), c);
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.first.second;
		if (v == g)
			break;
		for (int i = 0; i < G[v].size(); ++i) {
			edge e = G[v][i];
			if (c > 0 && d[e.to_] > d[v] + e.cost_ / 2) {
				d[e.to_] = d[v] + e.cost_ / 2;
				que.emplace(std::make_pair(d[e.to_], e.to_), c - 1);
			}
			if (d[e.to_] > d[v] + e.cost_) {
				d[e.to_] = d[v] + e.cost_;
				que.emplace(std::make_pair(d[e.to_], e.to_), c);
			}
		}
	}
	return d[g];
}

int main() {
	int m, s, g;
	std::cin >> c >> n >> m >> s >> g;
	--s;
	--g;
	int a, b, f;
	for (int i = 0; i < m; ++i) {
		std::cin >> a >> b >> f;
		--a;
		--b;
		G[a].push_back(edge(b, f));
		G[b].push_back(edge(a, f));
	}

	std::cout << dijkstra(s, g) << std::endl;
	for (int i = 0; i < n; ++i)
		std::cout << d[i] << ' ';
	std::cout << std::endl;
	return 0;
}