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 <iostream>
#include <algorithm>
 
using namespace std;
 
const int INF = 1000000000;
 
int c, n, m, s, d;
int visited[100][11];
int edge[100][100];
 
 
void dfs(int p, int rem, int cost){
   if(visited[p][rem] < cost) return;
   visited[p][rem] = cost;
   if(p == d) return;
   for(int i=0;i<n;i++){
      if(edge[p][i] == INF) continue;
      if(rem > 0 ) dfs(i, rem-1, cost+(edge[p][i]/2));
      dfs(i, rem, cost+edge[p][i]);
   }
}
 
main(){
   while(cin >> c >> n >> m >> s >> d && (c || n || m || s || d)){
      fill(edge[0], edge[100], INF);
      fill(visited[0], visited[100], INF);
      --s; --d;
      for(int i=0;i<m;i++){
         int a, b, f;
         cin >> a >> b >> f;
         --a; --b;
         edge[a][b] = edge[b][a] = f;
      }
      dfs(s, c, 0);
      int ans = INF;
      for(int i=0;i<c;i++){
         ans = min(ans, visited[d][i]);
      }
      cout << ans << endl;
   }
   return 0;
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int c,n,m,s,e;
    while(cin>>c>>n>>m>>s>>e,c+n+m+e+s){
        --s,--e;
        vector<vector<pii>>edge(n,vector<pii>());
        rep(i,m){
            int a,b,cost; cin>>a>>b>>cost;
            --a,--b;
            edge[a].push_back(pii(b,cost));
            edge[b].push_back(pii(a,cost));
        }
        typedef  pair<pii,int>piii;
        priority_queue<piii,vector<piii>,greater<piii>>que;
        vector<vector<int>>d(n,vector<int>(11,INF));
        que.push(piii(pii(0,c),s));
        d[s][c]=0;
        while(!que.empty()){
            piii now=que.top(); que.pop();
            if(d[now.second][now.first.second]<now.first.first)continue;
            for(int i=0; i<edge[now.second].size();i++){
                pii next=edge[now.second][i];
                if(d[next.first][now.first.second]>d[now.second][now.first.second]+next.second){
                    d[next.first][now.first.second]=d[now.second][now.first.second]+next.second;
                    que.push(piii(pii(d[next.first][now.first.second],now.first.second),next.first));
                }
                if(now.first.second>0){
                    if(d[next.first][now.first.second-1]>d[now.second][now.first.second]+(next.second)/2){
                        d[next.first][now.first.second-1]=now.first.first+(next.second)/2;
                        que.push(piii(pii(d[next.first][now.first.second-1],now.first.second-1),next.first));
                    }
                }
            }
        }
        int ans=INF;
        for(int i=0; i<=c; i++)cmin(ans,d[e][i]);
        cout<<ans<<endl;
    }
}

C++: #include <bits/stdc++.h>

using namespace std;

#define MAX 120
#define INF 1e9

struct Edge{
  int to,cost;
  Edge(int t,int c) : to(t),cost(c) {}
};

struct State{
  int cost,v,tic;
  State(int c,int v,int t) : cost(c),v(v),tic(t) {}
  bool operator < (const State &s)const{
    return cost > s.cost;
  }
};

int C,V,E,src,dst;
vector<Edge> G[MAX];

int dijkstra(){
  priority_queue<State> Q;
  Q.push(State(0,src,C));
  int dist[MAX][11];
  fill(dist[0],dist[0]+MAX*11,INF);
  dist[src][C] = 0;
  
  while(!Q.empty()){
    State s = Q.top(); Q.pop();
    int v = s.v,t = s.tic;
    if(dist[v][t] < s.cost) continue;
    if(v == dst) return dist[v][t];
    
    for(int i = 0 ; i < (int)G[v].size() ; i++){
      Edge e = G[v][i];
      if(dist[v][t] + e.cost < dist[e.to][t]){
        dist[e.to][t] = dist[v][t] + e.cost;
        Q.push(State(dist[e.to][t],e.to,t));
      }
      if(t > 0){
        if(dist[v][t] + e.cost/2 < dist[e.to][t-1]){
          dist[e.to][t-1] = dist[v][t] + e.cost/2;
          Q.push(State(dist[e.to][t-1],e.to,t-1));
        }
      }
    }
  }
}

int main(){
  while(cin >> C >> V >> E >> src >> dst, C){
    src--; dst--;
    for(int i = 0 ; i < V ; i++){
      G[i].clear();
    }
    for(int i = 0 ; i < E ; i++){
      int a,b,c;
      cin >> a >> b >> c; a--; b--;
      G[a].push_back(Edge(b,c));
      G[b].push_back(Edge(a,c));
    }
    cout << dijkstra() << endl;
  }
  return 0;
}