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]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 <queue>
#include <algorithm>
#include <functional>
using namespace std;

int C, N, M, S, D; //??????????????°???????????°???????????°???????????°???????????°
int cost[101];
int INF = 999999999;

class Edge
{
public:
	int to, cost;
	Edge(int to, int cost) : to(to), cost(cost){}
};

class Vertax
{
public:
	int n;
	int cost;
	priority_queue<int, vector<int>, greater<int>> discount;
	Vertax(){}

	Vertax get(Edge e)
	{
		Vertax v = *this;
		if (discount.size() == C)
		{
			v.cost += e.cost / 2;
			v.discount.push(e.cost);
			v.cost += discount.top() / 2;
			v.discount.pop();
		}
		else
		{
			v.cost += e.cost / 2;
			v.discount.push(e.cost);
		}
		v.n = e.to;
		return v;
	}
};

bool operator > (Vertax v1, Vertax v2)
{
	return (v1.cost > v2.cost);
}
bool operator < (Vertax v1, Vertax v2)
{
	return (v1.cost < v2.cost);
}

priority_queue<Vertax, vector<Vertax>, greater<Vertax>> que;

int main()
{
	while (cin >> C >> N >> M >> S >> D, C + N + M + S + D)
	{
		fill(cost + 1, cost + N + 1, INF);
		vector<Edge> e[101];

		for (int i = 0; i < M; i++)
		{
			int from, to, cost;
			cin >> from >> to >> cost;
			e[from].push_back(Edge(to, cost));
			e[to].push_back(Edge(from, cost));
		}

		Vertax start;
		start.n = S;
		start.cost = 0;
		que.push(start);
		cost[S] = 0;

		while (!que.empty())
		{
			Vertax v = que.top();
			que.pop();

			for (int i = 0; i < e[v.n].size(); i++)
			{
				Edge edge = e[v.n][i];
				Vertax next = v.get(edge);
				if (cost[next.n] > next.cost)
				{
					cost[next.n] = next.cost;
					que.push(next);
				}
			}
		}

		cout << cost[D] << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#define INF 1000000000;
#define dis first
#define mati second.first
#define sta  second.second
using namespace std;
typedef pair <int ,pair <int,int> > P;
vector <P> mp[102];
int c,n,m,start,goal;

int bit_count(int a) {
  a = (a & 0x55555555)+((a & 0xAAAAAAAA) >> 1 );
  a = (a & 0x33333333)+((a & 0xCCCCCCCC) >> 2 );
  a = (a & 0x0F0F0F0F)+((a & 0xF0F0F0F0) >> 4 );
  a = (a & 0x00FF00FF)+((a & 0xFF00FF00) >> 8 );
  a = (a & 0x0000FFFF)+((a & 0xFFFF0000) >> 16);
  return a;
}
int dijkstra() {
  int flg[12][102] = {},dis[12][102];
  for(int j=0;j<=c;j++)
    for(int i=0;i<=n;i++) dis[j][i] = -INF;

  for(int j=1;j<=c;j++)flg[j][start] = 1;

  priority_queue <P> Q;
  P t;
  t.dis = 0, t.mati = start, t.sta = 0;
  Q.push(t);

  while(!Q.empty()) {
    t = Q.top(),Q.pop();
    if(flg[t.sta][t.mati] == 1) continue;
    flg[t.sta][t.mati] = 1;
    for(int i=0;i<mp[t.mati].size();i++){
      int ndis = mp[t.mati][i].dis;
      int nmati = mp[t.mati][i].mati;
      int nsta = t.sta+1;
      P tt;
      if(dis[t.sta][nmati] < t.dis-ndis && flg[t.sta][nmati] == 0) {
	tt.dis = t.dis-ndis,tt.mati = nmati,tt.sta = t.sta;
	dis[t.sta][nmati] = t.dis-ndis;
	Q.push(tt);
      }
      if(nsta<= c&&dis[nsta][nmati]<t.dis-ndis/2 && flg[nsta][nmati]==0){
	tt.dis = t.dis - ndis/2 , tt.mati = nmati, tt.sta = nsta;
	dis[nsta][nmati] = t.dis-ndis/2;
	Q.push(tt);
      }
    }
  }

  int ans = -INF;
  for(int j=0;j<=c;j++)ans = max(ans,dis[j][goal]);
   
  return -ans;
}


int main() {

  while(1) {
    cin >> c >> n >> m >> start >> goal;
    if(c==0&&n==0&&m==0&&start==0&&goal==0) break;

    for(int i=0;i<=n;i++) mp[i].clear();
    for(int i=0;i<m;i++) {
      int a,b,f;
      cin >> a >> b >> f;
      P t;
      t.dis = f,  t.mati = b , t.sta = 0;
      mp[a].push_back(t);
      t.mati = a;
      mp[b].push_back(t);
    }

    cout << dijkstra() << endl;
  }

  return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>

#define FOR(i,b,n) for(int i=b;i<n;i++)
#define RFOR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))

#define INF 100000000

using namespace std;

typedef pair<int,int> paii;

int c, n, m, s, d; 
int fare[1000][1000];
int vtx[1000][1000];
	
int solve()
{
	queue<paii> qu;
	CLR(vtx);
	
	FOR(i, 1, n+1)
	{
		FOR(j, 0, c+1)
		{
			if( i != s )
				vtx[i][j] = INF;
		}
	}
	
	qu.push(paii(s, c));
	
	while( !qu.empty() )
	{
		int nowv = qu.front().first;
		int nowt = qu.front().second;
		qu.pop();
		
		FOR(j, 1, n+1)
		{
			if(( j != nowv) && (fare[nowv][j] != 0))
			{
				if( vtx[j][nowt] > vtx[nowv][nowt] + fare[nowv][j] )
				{
					vtx[j][nowt] = vtx[nowv][nowt] + fare[nowv][j];
					qu.push(paii(j,nowt));
				}
				
				if( (nowt > 0) && (vtx[j][nowt-1] > vtx[nowv][nowt] + fare[nowv][j]/2) )
				{
					vtx[j][nowt-1] = vtx[nowv][nowt] + fare[nowv][j]/2;
					qu.push(paii(j,nowt-1));
				}
			}
		}
	}
	
	int res = INF;
	
	FOR(i, 0, c)
	{
		res = min(res, vtx[d][i]);
	}
	
	return res;
}

int main()
{
	while(cin >> c >> n >> m >> s >> d, (c||n||m||s||d))
	{
		CLR(fare);
		
		FOR(i, 0, m)
		{
			int a, b, f;
			cin >> a >> b >> f;
			
			fare[a][b] = f;
			fare[b][a] = f;
		}
		
		cout << solve() << endl;
	}
	
	return 0;
}