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 <algorithm>
#define MAX 100
#define INF 999999

using namespace std;

bool visit[MAX + 1][MAX + 1];
int v[MAX + 1][MAX + 1];
int rote[MAX + 1][MAX + 1];
int c,n,m,s,d,a,b,f,x,y;

int dijkstra(void){

  fill( v[0] , v[MAX + 1] , INF );
  fill( visit[0] , visit[MAX + 1] , false );

  v[c][s - 1] = 0;

  while(1){

    int min_i = -1, min_j;

    for( int i = y ; i <= x ; i++ ){
      for( int j = 0 ; j <= c ; j++ ){
	if( (v[j][i] < v[min_i][min_j] || min_i == -1) && !visit[j][i] ){
	  min_i = i;
	  min_j = j;
	}
      }
    }

    if( min_i == -1 ) break;
    visit[min_j][min_i] = true;

    for( int i = y ; i <= x ; i++ ){
      v[min_j][i] = min( v[min_j][i] , v[min_j][min_i] + rote[min_i][i] );
      if( min_j > 0 ){
	v[min_j - 1][i] = min( v[min_j - 1][i] , v[min_j][min_i] + rote[min_i][i]/2 );
      } 
    }


  }

  int ans = INF;
  for( int i = 0 ; i <= c ; i++ ){
    ans = min( ans , v[i][d - 1] );
  }
  return ans;
}



int main(void){

  fill( rote[0] , rote[MAX] , INF );
  
  while( cin >> c >> n >> m >> s >> d , c + n + m + s + d ){
    
    x = 0;
    y = INF;
    
    for( int i = 0 ; i < m ; i++ ){
      cin >> a >> b >> f;
      rote[a - 1][b - 1] = rote[b - 1][a - 1] = f;
      x = max( x , max(a - 1 , b - 1) );
      y = min( y , min(a - 1 , b - 1) );
    }

    cout << dijkstra() << endl;

  }
  return 0;
}