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<bits/stdc++.h>
#define MAX_V 101
using namespace std;

struct edge { 
  int to, cost;
  edge(){}
  edge(int to,int cost):to(to),cost(cost){};
};
typedef pair<int ,int> P;
const int INF = 1 << 30;
int V; //ノードの数
vector<edge> Graph[MAX_V];
int min_cost[11][MAX_V];

int c,m,s,d;
void Dijkstra(int s,int chip){ // s:スタートからの最小コストをmin_costに設定
  priority_queue<P,vector< P >, greater<P> > que;
  fill(min_cost[chip],min_cost[chip] + V,INF);
  min_cost[chip][s] = 0;
  que.push(P(0,s));
  
  while(!que.empty()){
    P p = que.top();que.pop();
    int now = p.second;
    int cost = p.first;
    if(min_cost[chip][now] < cost) continue;
    
    for(int i = 0; i < Graph[now].size(); i++){
      edge e = Graph[now][i];
      int a;
      if(chip == 0){
	a = min_cost[chip][now] + e.cost;
      }else{
	a = min(min_cost[chip][now] + e.cost, min_cost[chip-1][now] + e.cost / 2);
	if(min_cost[chip][e.to] > a){
	  min_cost[chip][e.to] = a;
	  que.push(P(min_cost[chip][e.to], e.to));
	}
      }
    }
  }
}

int main(){
  
  while(cin >> c >> V >> m >> s >> d && (c||V||m||s||d)){
    s--;
    d--;
    
    for(int i=0;i<m;i++){
      int a,b,f;
      cin>>a>>b>>f;
      a--;b--;
      Graph[a].push_back(edge(b,f));
      Graph[b].push_back(edge(a,f));
    }
    
    for(int i=0;i<=c;i++){
      Dijkstra(s,i);
    }

    cout<<min_cost[c][d]<<endl;
    
    for(int i=0;i<MAX_V;i++) Graph[i].clear();
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
#include<vector>
#include<math.h>

int main(){

return 0;
}

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