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++: #include<iostream>
#include<algorithm>
using namespace std;
const int INF = (1<<21);
int c,n,m,s,d;
int G[100][100];


int dij(){
  int D[100][11];
  bool V[100][11];
  for(int i=0;i<n;i++){
    for(int j=0;j<c+1;j++){
      D[i][j]=INF;
      V[i][j]=false;
    }
  }
    
  D[s][c]=0;
  while(1){
    int minv=INF,u,v;
    for(int i=0;i<n;i++){
      for(int j=0;j<c+1;j++){
	if(!V[i][j] && D[i][j]<minv){
	  minv=D[i][j];
	  u=i;
	  v=j;
	}
      }
    }

    if(minv==INF){
      break;
    }

    V[u][v]=true;
    for(int i=0;i<n;i++){
      if(G[u][i]==INF) continue;
      D[i][v]=min(D[i][v],D[u][v]+G[u][i]);
      if( v ){
	D[i][v-1]=min(D[i][v-1],D[u][v]+(G[u][i]/2));
      } 
    }
  }
    
    int minv=INF;
    for(int i=0;i<c+1;i++){
      minv=min(minv,D[d][i]);
    }
    return minv;
}



int main(){
  
  while(cin>> c>> n>> m>> s>> d,c){
    s--;
    d--;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	G[i][j]=INF;
      }
    }

    for(int i=0;i<m;i++){
      int a,b,f;
      cin>> a>> b>> f;
      G[a-1][b-1]=G[b-1][a-1]=f;
    }

    cout<< dij()<< endl;
  }
}