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>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int INF = 1 << 25;
int dist[100][11];

struct State {
	int v, c, d;
	bool operator <(const State& x) const {
		return d > x.d;
	}
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int c, n, m, s, g;
	while(cin >> c >> n >> m >> s >> g, n) {
		s--, g--;

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

		fill((int*)begin(dist), (int*)end(dist), INF);
		dist[s][c] = 0;
		priority_queue<State> q;
		q.push({ s, c, 0 });
		while(q.size()) {
			int v = q.top().v, rem = q.top().c, d = q.top().d;
			q.pop();
			if(dist[v][c] < d) continue;
			for(auto e : G[v]) {
				int cost[2] = { e.second, e.second / 2 };
				for(int i = 0; i < 2; i++) {
					int u = e.first;
					if(rem == 0 && i == 1) continue;
					if(dist[u][rem - i] > d + cost[i]) {
						dist[u][rem - i] = d + cost[i];
						q.push({ u, rem - i, d + cost[i] });
					}
				}
			}
		}

		int ans = 1e9;
		for(int i = 0; i <= c; i++) {
			ans = min(ans, dist[g][i]);
		}

		cout << ans << endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

vector<int> dijk(int s, int v, vector<vector<pair<int, int>>> adjlist){
    priority_queue <pair<int, int>> wait;
    vector<int> result(v, INF);

    result[s] = 0;
    wait.push(make_pair(0,s));

    while(!wait.empty()){
        int nowpoint = wait.top().second;
        int nowcost = -wait.top().first;
        wait.pop();

        if(result[nowpoint] < nowcost) continue;

        for(int i = 0; i < adjlist[nowpoint].size(); i++){
            int nextpoint = adjlist[nowpoint][i].second;
            int nextcost = nowcost + adjlist[nowpoint][i].first;
            if(result[nextpoint] > nextcost){
                result[nextpoint] = nextcost;
                wait.push(make_pair(-nextcost, nextpoint));
            }
        }
    }
    return result;
}



signed main(){
    

    while(1){
    int c, n, m, s, t; cin >> c >> n >> m >> s >> t;
    s--;
    t--;
    if(!n) break;
    vector<vector<int> > toNode(n, vector<int> (c + 1));
    int num = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= c; j++){
            toNode[i][j] = num;
            num++;
        }
    }

    vector<vector<pair<int, int>>> adj(num);

    for(int i = 0; i < m; i++){
        int a, b, f; cin >> a >> b >> f;
        a--;
        b--;

        for(int iii = 0; iii < 2; iii++){

            for(int j = 0; j <= c; j++){
                    
                int cur = toNode[a][j];
                // 使わない
                int nxt = toNode[b][j];
                adj[cur].push_back({f, nxt});
                
                nxt = toNode[b][j + 1];
                // 使う
                if(j != c){
                    adj[cur].push_back({f / 2, nxt});
                }
            }
            swap(a, b);
        }
    }

    
    int ans = INF;
    int S = toNode[s][0];
    vector<int> result = dijk(S, num, adj);
    for(int j = 0; j <= c; j++){
        int G = toNode[t][j];
        ans = min(ans, result[G]);
    }

    cout << ans << endl;
    }
    return 0;
}

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

#define INF 1 << 29

using namespace std;

int c,n,m,s,d;
int cost[101][101];

class S{
public:
    int node;
    int tick;
    int cost;

    S(int node,int tick,int cost):
        node(node),tick(tick),cost(cost){}
    S(){}
    bool operator <(const S arg) const{
        return cost > arg.cost;
    }
};

int dijkstra(int src,int dst){
    priority_queue<S> q;
    int memo[n+1][c+1];
    S tmp;
    fill((int *)memo, (int *)memo+(n+1)*(c+1), INF);
    memo[src][c] = 0;
    q.push(S(src,c,0));

    while(!q.empty()){
        tmp = q.top();
        q.pop();
        for(int i=0;i<=n;i++){
            if(cost[tmp.node][i] != INF){
                if(cost[tmp.node][i] + tmp.cost < memo[i][tmp.tick]){
                    q.push(S(i,tmp.tick,cost[tmp.node][i] + tmp.cost));
                    memo[i][tmp.tick] = cost[tmp.node][i] + tmp.cost;
                }
                if(tmp.tick && cost[tmp.node][i]/2 + tmp.cost < memo[i][tmp.tick-1]){
                    q.push(S(i,tmp.tick-1,cost[tmp.node][i]/2 + tmp.cost));
                    memo[i][tmp.tick-1] = cost[tmp.node][i]/2 + tmp.cost;
                }
            }
        }
    }
    int ret = 1<<29;
    for(int i=0;i<=c;i++){
        ret = min(ret, memo[dst][i]);
    }
    return ret;
}

int main(){
    while(cin >> c >> n >> m >> s >> d){
        if((c|n|m|s|d) == 0) break;
        int src,dst,c;
        fill((int *)cost, (int *)cost+101*101, INF);
        for(int i=0;i<m;i++){
            cin >> src >> dst >> c;
            cost[src][dst] = c;
            cost[dst][src] = c;
        }

        cout << dijkstra(s,d) << endl;
    }
}