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 <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

#define NONE -1

// c: øÌ 1`10
// n: oXªÂÈ®¬Ì 2`100
// m: oXÌHü 1`500
// s: start
// d: goal
int c, n, m, s, d;

// ÅZoHTõ - Ï
vector < vector <int> >	edges;

int search()
{
	// Å¬l
	vector < vector <int> >		D( n, vector <int>(c+1,NONE) );
	// KâÏÝÌm[h
	vector < vector <bool> >	V( n, vector <bool>(c+1,false) );

	D[s][c] = 0;

	while (1)
	{
		int u, w, minv = NONE;
		for ( int i = 0; i < n; i++ )
		{
			for ( int j = 0; j < c+1; j++ )
			{
				if ( V[i][j] == false && D[i][j] != NONE && ( minv == NONE || minv > D[i][j] ) )
				{
					minv = D[i][j];
					u = i;
					w = j;
				}
			}
		}
		if ( minv == NONE )
			break;

		V[u][w] = true;

		for ( int v = 0; v < n; v++ )
		{
			if ( edges[u][v] == NONE )
				continue;

			if ( D[v][w] == NONE )
				D[v][w] = D[u][w] + edges[u][v];
			else
				D[v][w] = min( D[v][w], D[u][w] + edges[u][v] );

			if ( w )
			{
				if ( D[v][w-1] == NONE )
					D[v][w-1] = D[u][w] + edges[u][v]/2;
				else
					D[v][w-1] = min(D[v][w-1], D[u][w] + edges[u][v]/2);
			}
		}

	}

	int minv = NONE;
	for ( int i = 0; i < c+1; i++ )
	{
		if ( D[d][i] != NONE )
		{
			if ( minv == NONE )
				minv = D[d][i];
			else
				minv = min( minv, D[d][i] );
		}
	}
	return minv;

}

int main( void )
{
	while ( cin >> c >> n >> m >> s >> d && c && n && m && s && d )
	{
		edges	=	vector < vector <int> >( 101, vector <int>(101, NONE) );
		s--;
		d--;


		// ú»
		for ( int i = 0; i < m; i++ )
		{
			// f: a-bÔÌRXg
			int a, b, f;
			cin >> a >> b >> f;

			a--;
			b--;

			edges[a][b] = f;
			edges[b][a] = f;

		}


		// Tõ
		int kotae = search();
		cout << kotae << endl;

	}

	return 0;
}

C++: #include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T = lint>
struct Edge {
	int to;
	T cost;
	Edge() {}
	Edge(int to, T cost) : to(to), cost(cost) {}
	bool operator>(const Edge &r) const { return this->cost > r.cost; }
};

template<class T>
vector<T> Dijkstra(vector<vector<Edge<T>>> &edges, int st) {

	int V = (int)edges.size();
	const T inf = numeric_limits<T>::max() / 2;
	vector<T> cost(V, inf);
	cost[st] = 0;

	priority_queue<Edge<T>, vector<Edge<T>>, greater<Edge<T>>> p_que;
	p_que.emplace(st, cost[st]);

	while (!p_que.empty()) {

		Edge<T> now(p_que.top().to, p_que.top().cost);
		p_que.pop();

		if (cost[now.to] < now.cost) continue;
		for (const Edge<T> &e : edges[now.to]) {
			T tmp_cost = now.cost + e.cost;
			if (cost[e.to] > tmp_cost) {
				cost[e.to] = tmp_cost;
				p_que.emplace(e.to, cost[e.to]);
			}
		}
	}

	return cost; // min cost to vertex idx from st
}

template<class T>
inline bool chmin(T &a, T b) { return a > b && (a = b, true); }

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	while (true) {

		int c, n, m, s, d;
		cin >> c >> n >> m >> s >> d;
		if (c == 0) break;
		s--, d--;

		vector<vector<Edge<int>>> edges(n*(c + 1));
		for (int i = 0; i < m; i++) {
			int u, v, len;
			cin >> u >> v >> len;
			u--, v--;
			for (int j = 0; j <= c; j++) {
				edges[u * (c + 1) + j].emplace_back(v * (c + 1) + j, len);
				edges[v * (c + 1) + j].emplace_back(u * (c + 1) + j, len);
				if (j != c) {
					edges[u * (c + 1) + j].emplace_back(v * (c + 1) + (j + 1), len / 2);
					edges[v * (c + 1) + j].emplace_back(u * (c + 1) + (j + 1), len / 2);
				}
			}
		}

		auto cost = Dijkstra(edges, s * (c + 1));

		int ans = INF;
		for (int i = 0; i <= c; i++) chmin(ans, cost[d*(c + 1) + i]);

		cout << ans << "\n";
	}

	return 0;
}