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 <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
const int MAX_N = 110;
struct edge
{
    int to, cost, card;
    bool operator<(const edge &a) const { return cost > a.cost; }
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int c, n, m, s, d;
    while (cin >> c >> n >> m >> s >> d, c | n | m)
    {
        s--, d--;
        vector<edge> G[MAX_N];
        for (int i = 0; i < m; i++)
        {
            int a, b, f;
            cin >> a >> b >> f;
            a--, b--;
            G[a].push_back({b, f, 0});
            G[b].push_back({a, f, 0});
            G[a].push_back({b, f / 2, 1});
            G[b].push_back({a, f / 2, 1});
        }
        priority_queue<edge> que;
        vector<vector<int>> dist(n, vector<int>(15, INF));
        dist[s][c] = 0;
        que.push({s, 0, c});
        while(que.size())
        {
            edge p = que.top(); que.pop();
            for(int u = 0; u < G[p.to].size(); u++)
            {
                edge e = G[p.to][u];
                int num = p. card - e.card;
                if(num < 0) continue;
                if(e.cost + dist[p.to][p.card] < dist[e.to][num])
                {
                    dist[e.to][num] = dist[p.to][p.card] + e.cost;
                    que.push({e.to, dist[e.to][num], num});
                }
            }
        }
        int ans = INF;
        for(int i = 0; i < 15; i++) ans = min(ans, dist[d][i]);
        cout << ans << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX 100000
#define MAX_NODE_ID 100
#define MAX_TICKET 10
class Node{
public:
	int id;
	int cost;
	int ticket;
	Node(int i,int c,int t){
		id=i;
		cost=c;
		ticket=t;
	}
	bool operator < (const Node &o) const{
		return cost > o.cost;
	}
};
typedef priority_queue<Node> PQ;
int table[MAX_NODE_ID][MAX_NODE_ID];
bool visited[MAX_NODE_ID][MAX_TICKET];
int main(){

	for(int c,n,m,s,d;cin>>c>>n>>m>>s>>d&&(c||n||m||s||d);){
		for(int i=0;i<MAX_NODE_ID;i++)for(int j=0;j<MAX_NODE_ID;j++)table[i][j]=MAX;
		for(int i=0,a,b,f;i<m&&cin>>a>>b>>f;i++){
			table[a][b]=f;
			table[b][a]=f;
//			cout<<"table["<<a<<"]["<<b<<"]"<<table[a][b]<<endl;
//			cout<<"table["<<b<<"]["<<a<<"]"<<table[b][a]<<endl;
		}
		PQ pq;
		Node start(s,0,c);
		pq.push(start);
		while(!pq.empty()){
//			cout<<"current:"<<current_node<<endl;
			if(pq.top().id==d)break;
			if(visited[pq.top().id][pq.top().cost]);
			else{
				for(int i=1;i<=n;i++){
					if(pq.top().id==i)continue;
					if(table[pq.top().id][i]==MAX)continue;
	//				cout<<"["<<current_node<<"]["<<i<<"]"<<"cost:"<<table[current_node][i]<<endl;
					Node node1(i,pq.top().cost+table[pq.top().id][i],pq.top().ticket);
					pq.push(node1);
					if(pq.top().ticket>0){
						Node node2(i,pq.top().cost+(table[pq.top().id][i]/2),pq.top().ticket-1);
						pq.push(node2);
					}
					visited[pq.top().id][i]=true;
				}
			}
			pq.pop();
		}
		cout<<pq.top().cost<<endl;
	}


	return 0;
}

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[101];

		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;
}