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]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++: //Solution for aoj:0212 Highway Express Bus
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
using namespace std;
typedef pair<int, int>P;


struct S {
	int cost, to, num, jud;
	S(int c, int t, int n, int j) : cost(c), to(t), num(n), jud(j) {}
	bool operator>(const S &s) const {
		return cost > s.cost;
	}
};

const int INF = 1 << 31;
int c, n, m, s, d, w;
int tocost[101][11];
vector<P> town[101];
priority_queue<S, vector<S>, greater<S> > pq;

void pq_set(int p, int sum, int j){
	for (int i = 0; i < town[p].size(); i++){
			pq.push(S(town[p][i].second + sum, town[p][i].first, j, 0));
			if (j)
				pq.push(S(town[p][i].second / 2 + sum, town[p][i].first, j - 1, 1));
	}
}

void dijkstra(){
	while (!pq.empty()){
		S a = pq.top();
		pq.pop();
		if (a.jud){
			if (tocost[a.to][a.num] < a.cost&&a.to!=s){
				tocost[a.to][a.num] = a.cost;
					pq_set(a.to, tocost[a.to][a.num], a.num);

			}
		}
			else{
				if (tocost[a.to][a.num] < a.cost&&a.to!=s){
					tocost[a.to][a.num] = a.cost;
					pq_set(a.to, tocost[a.to][a.num], a.num);
					
				}
			}
	}
}
	int main(){
		while (cin >> c >> n >> m >> s >> d&&c){
			for (int i = 0; i < 101; i++)
				fill(tocost[i], tocost[i] + 11, INF);
			fill(tocost[s], tocost[s] + 11, 0);
			while (pq.size())
				pq.pop();
			for (int i = 0; i < n; i++)
					town[i].erase(town[i].begin(),town[i].end());
			for (int i = 0; i < m; i++){
				int a, b, c;
				cin >> a >> b >> c;
				town[a].push_back({ b, c*-1 });
				town[b].push_back({ a, c*-1 });
			}
			pq_set(s, 0, c);
			dijkstra();
			cout << -tocost[d][0] << endl;
		}
	}

C++: #include <iostream>
#include <queue>
#include <vector>
using namespace std;

int C,N,M,S,D;

class Node
{
	public:
		
		vector<int> to,c;
};

class State
{
	public:

		int p,c,k;
		State(int P, int C, int K)
		{
			p=P; c=C; k=K;
		}

		bool operator<(const State &s) const
		{
			if(c!=s.c) return c>s.c;
			return k>s.k;
		}
};



int main()
{
	while(cin>>C>>N>>M>>S>>D, C||N||M||S||D)
	{
		int v[100][10] = {0};
		Node node[100];

		S--; D--;
		for(int i=0; i<M; i++)
		{
			int x,y,z;
			cin>>x>>y>>z;
			x--; y--;
			node[x].to.push_back(y);
			node[y].to.push_back(x);
			node[x].c.push_back(z);
			node[y].c.push_back(z);
		}

		priority_queue<State>	 q;
		q.push(State(S,0,0));
		while(!q.empty())
		{
			State t=q.top(); q.pop();
			if(t.p==D)
			{
				cout << t.c << endl;
				break;
			}

			if(v[t.p][t.k]) continue;
			v[t.p][t.k] = 1;

			for(int i=0; i<node[t.p].to.size(); i++)
			{
				q.push(State(node[t.p].to[i], t.c+node[t.p].c[i], t.k));
				if(t.k<C)
				{
					q.push(State(node[t.p].to[i], t.c+node[t.p].c[i]/2, t.k+1));
				}
			}
		}


	}
}

C++: #include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> PP;
int graph[110][110];
int c,n,m,s,d;
int D[110][15];
const int INF = 1<<28;

void Init(){
  for(int i=0;i<110;i++){
    for(int k=0;k<110;k++){
      graph[i][k] = INF;
    }
    for(int j=0;j<15;j++){
      D[i][j] = INF;
    }
  }

}


void dijkstra(){
  priority_queue<PP,vector<PP>,greater<PP> > que;
  D[s][c] = 0;
  // PP( P(pos,cost), c )
  // .F.F -> pos
  // .F.S -> cost
  // .S   -> c
  que.push(PP(P(s,0),c));
  while(!que.empty() ){
    PP p = que.top();que.pop();
    int v = p.F.F;
    for(int i=1;i<=n;i++){
     
      if(D[i][p.S] > graph[v][i] + p.F.S){
	D[i][p.S] = graph[v][i] + p.F.S;
	que.push(PP(P(i,D[i][p.S]),p.S));
      }

      if(D[i][p.S-1] > graph[v][i]/2 + p.F.S && p.S != 0){
	D[i][p.S-1] = graph[v][i]/2 + p.F.S;
	que.push(PP(P(i,D[i][p.S-1]),p.S-1));
      }


    }


  }

}

int main(){
  int x,y,co;
  while(true){
    cin >> c >> n >> m >> s >> d;
    if(c+n+m+s+d == 0)break;
    Init();

    for(int i=0;i<m;i++){
      cin >> x >> y >> co;
      graph[x][y] = graph[y][x] = co;
    }


    dijkstra();
    int ans = INF;
    for(int i=0;i<=c;i++)ans = min(ans,D[d][i]);
    cout<< ans << endl;
  }
  return 0;
}


//Version.2

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef pair<int, int>P;

struct node {
	int first, second, c;
};
bool operator<(node a, node b) {
	return a.second > b.second;
}
vector<P>E[100];
int d[100][11];

int main() {
	int c, n, m, s, g;
	while (scanf("%d%d%d%d%d", &c, &n, &m, &s, &g), c) {
		s--; g--;
		rep(i, 100)E[i].clear();
		memset(d, 0x3f, sizeof(d));
		rep(i, m) {
			int a, b, f; scanf("%d%d%d", &a, &b, &f);
			a--; b--;
			E[a].push_back(P(b, f)); E[b].push_back(P(a, f));
		}
		priority_queue<node>que;
		que.push({ s,0,c });
		memset(d[s], 0, sizeof(d[s]));
		while (!que.empty()) {
			node p = que.top(); que.pop();
			if (d[p.first][p.c - 1] < p.second)continue;
			for (P i : E[p.first]) {
				if (p.c&& d[i.first][p.c - 1] > p.second + i.second / 2) {
					d[i.first][p.c - 1] = p.second + i.second / 2;
					que.push({ i.first, d[i.first][p.c - 1],p.c - 1 });
				}
				if (d[i.first][p.c] > p.second + i.second) {
					d[i.first][p.c] = p.second + i.second;
					que.push({ i.first, d[i.first][p.c],p.c });
				}
			}
		}
		int Min = INT_MAX;
		rep(i, c + 1)Min = min(Min, d[g][i]);
		printf("%d\n", Min);
	}
}