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

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

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