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