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

C++: #include<bits/stdc++.h>
using namespace std;
struct NODE{
  int to,cost,tick;
  NODE(int to,int cost,int tick) : to(to),cost(cost),tick(tick){}
  NODE(){}
  bool operator < (const NODE &a)const{
    return cost > a.cost;
  }
};
int main(){
  int c,n,m,s,d,a,b,f;
  while(cin>>c>>n>>m>>s>>d&&c&&n&&m&&s&&d){
    vector<NODE> edge[101];
    
    for(int i=0;i<m;i++){
      cin >> a >> b >> f;
      edge[a].push_back(NODE(b,f,-1));
      edge[b].push_back(NODE(a,f,-1));
    }
    bool done[101][20] = {};
    priority_queue<NODE> Q;
    Q.push(NODE(s,0,c));
    while(!Q.empty()){
      NODE q = Q.top();Q.pop();
      if(done[q.to][q.tick] == true)continue;
      done[q.to][q.tick] = true;
      if(q.to == d){
	cout << q.cost << endl;
	break;
      }
      for(int i=0;i<edge[q.to].size();i++){
	Q.push(NODE(edge[q.to][i].to,q.cost + edge[q.to][i].cost,q.tick));
	if(q.tick){
	  Q.push(NODE(edge[q.to][i].to,q.cost + (edge[q.to][i].cost/2),q.tick-1));
	}
      }
    }
  }
}