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<queue>
#include<vector>
#include<algorithm>
using namespace std;
#define INF (1<<24)

struct state{
  int cost,pos,cnt;
  bool operator < (const state &p) const{
    return cost>p.cost;
  }
};

struct edge{
  int to,cost;
};

int c,n,m,s,d;
vector<edge> G[100];

void init(){
  for(int i=0;i<100;i++)G[i].clear();
}

int dijkstra(int si,int ti){
  int d[100][11];
  for(int i=0;i<100;i++)
    for(int j=0;j<11;j++)d[i][j]=INF;

  d[si][c]=0;
  priority_queue< state > Q;
  Q.push((state){0,si,c});

  while(!Q.empty()){
    state s=Q.top();Q.pop();
    if(s.cost>d[s.pos][s.cnt])continue;

    for(int i=0;i<(int)G[s.pos].size();i++){
      edge e=G[s.pos][i];
      if(s.cost+e.cost>=d[e.to][s.cnt])continue;
      d[e.to][s.cnt]=s.cost+e.cost;
      Q.push((state){s.cost+e.cost,e.to,s.cnt});
    }

    if(s.cnt==0)continue;

    for(int i=0;i<(int)G[s.pos].size();i++){
      edge e=G[s.pos][i];
      if(s.cost+e.cost/2>=d[e.to][s.cnt-1])continue;
      d[e.to][s.cnt-1]=s.cost+e.cost/2;
      Q.push((state){s.cost+e.cost/2,e.to,s.cnt-1});
    }
  }//while

  int res=INF;
  for(int i=0;i<=c;i++){
    res=min(res,d[ti][i]);
  }
  return res;
}

int main(){
  int a,b,f;
  while(cin>>c>>n>>m>>s>>d){
    if(n==0)break;
    init();
    for(int i=0;i<m;i++){
      cin>>a>>b>>f;
      a--;b--;
      G[a].push_back((edge){b,f});
      G[b].push_back((edge){a,f});
    }
    cout<<dijkstra(s-1,d-1)<<endl;
  }
  return 0;
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <numeric>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 10007;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);

typedef std::pair<int, int> P;
typedef pair<int, P> pp;

const int smax = 100100;

vector<P> edge[smax];
int c, n, m, s, d; // c...??????????????° n...?????? m...??? s...????????? d...?????? 
LL v[15][smax]; //15....max of tickets

int solve() {
	v[c][s] = 0; //?????????
	priority_queue<pp, vector<pp>, greater<pp> > q;
	q.push(pp(0, P(s, c))); //cost,now,ticket(now)
	while (!q.empty()) {
		pp V = q.top();
		q.pop();
		int now_v = V.second.first;
		int now_t = V.second.second;
		if (v[now_t][now_v] < V.first) continue; //v.first(?????????)???v[now_t][now_v]???????????§????????£???????????????????????§?????????

												 //not use tickets
		for (int i = 0; i<edge[now_v].size(); i++) {
			if (v[now_t][edge[now_v][i].first] > v[now_t][now_v] + edge[now_v][i].second) {
				v[now_t][edge[now_v][i].first] = v[now_t][now_v] + edge[now_v][i].second;
				q.push(pp(v[now_t][now_v] + edge[now_v][i].second, P(edge[now_v][i].first, now_t)));
			}
		}

		// use tickets
		if (now_v > 0) {
			for (int i = 0; i<edge[now_v].size(); i++) {
				P p = edge[now_v][i];
				int next_c = p.second / 2;
				if (now_t == 0)continue;
				if (v[now_t - 1][p.first] > v[now_t][now_v] + next_c) {
					v[now_t - 1][p.first] = v[now_t][now_v] + next_c;
					q.push(pp(v[now_t - 1][p.first], P(p.first, now_t - 1)));
				}
			}
		}
	}
	LL ans = INF;
	for (int i = 0; i<c + 1; i++) {
		ans = min(ans, v[i][d]);
	}
	return ans;
}

int main(void) {
	while (cin >> c >> n >> m >> s >> d && c | n | m | s | d) {
		for (int i= 0; i < smax;i++) edge[i].clear();
		fill(v[0], v[0] + 15 * smax, INF);
		for (int i = 0; i < m;i++) {
			int a, b, f;
			cin >> a >> b >> f;
			edge[a].push_back(P(b, f));
			edge[b].push_back(P(a, f));
		}
		cout << solve() << endl;
	}
	return 0;
}

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

using namespace std;

struct edge {
    int to, cost;
    edge() {}
    edge(int to_, int cost_): to(to_), cost(cost_) {}
};

struct state {
    int pos, cost;
    state (){}
    state (int pos_, int cost_): pos(pos_), cost(cost_) {}

    bool operator < (const state& o) const {
        return cost > o.cost;
    }
};

constexpr int INF = 1 << 29;

int C, M, N, S, D;

const int W = 100;
vector<edge> graph[1100];

int min_cost[1100];

bool solve() {
    cin >> C >> N >> M >> S >> D;
    if (C+N+M+S+D == 0) { return false; }
    --S; --D;

    for (int j = 0; j < M; ++j) {
        int a, b, f; cin >> a >> b >> f;
        --a; --b;
        for (int j = 0; j < C; ++j) {
            graph[a+j*W].emplace_back(b+j*W, f);
            graph[b+j*W].emplace_back(a+j*W, f);

            graph[a+j*W].emplace_back(b+(j+1)*W, f/2);
            graph[b+j*W].emplace_back(a+(j+1)*W, f/2);
        }
    }

    fill(min_cost, min_cost+1000, INF);
    min_cost[S] = 0;

    priority_queue<state, vector<state>> que;
    que.emplace(S, 0);

    while (!que.empty()) {
        state st = que.top(); que.pop();
        int pos = st.pos;
        int cost = st.cost;
        if (cost > min_cost[st.pos]) { continue; }

        for (edge& e : graph[pos]) {
            int next_cost = cost + e.cost;
            if (next_cost < min_cost[e.to]) {
                min_cost[e.to] = next_cost;
                que.emplace(e.to, next_cost);
            }
        }
    }

    int ans = INF;
    for (int j = 0; j <= C; ++j) {
        ans = min(ans, min_cost[D+j*W]);
    }
    cout << ans << endl;

    return true;
}

int main() {
    for (; solve(); ) ;
    return 0;
}