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]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)
					}
				}
			}
		}
		runtime.GC()
	}
}

C++: #include<bits/stdc++.h>
#define MAX_V 101
using namespace std;

struct edge { 
  int to, cost;
  edge(){}
  edge(int to,int cost):to(to),cost(cost){};
};
typedef pair<int ,int> P;
const int INF = 1e+9;
int V; //ノードの数
vector<edge> Graph[MAX_V];
int min_cost[11][MAX_V];

int c,m,s,d;
void Dijkstra(int s,int chip){ // s:スタートからの最小コストをmin_costに設定
  priority_queue<P,vector< P >, greater<P> > que;
  min_cost[chip][s] = 0;
  que.push(P(0,s));
  
  while(!que.empty()){
    P p = que.top();que.pop();
    int now = p.second;
    int cost = p.first;
    if(min_cost[chip][now] < cost) continue;
    
    for(int i = 0; i < Graph[now].size(); i++){
      edge e = Graph[now][i];
      int a;
      if(chip == 0){
	a = min_cost[chip][now] + e.cost;
      }else{
	a = min(min_cost[chip][now] + e.cost, min_cost[chip-1][now] + e.cost / 2);
	if(min_cost[chip][e.to] > a){
	  min_cost[chip][e.to] = a;
	  que.push(P(min_cost[chip][e.to], e.to));
	}
      }
    }
  }
}

int main(){
  
  while(cin >> c >> V >> m >> s >> d && (c||V||m||s||d)){
    s--;
    d--;
    
    for(int i=0;i<m;i++){
      int a,b,f;
      cin>>a>>b>>f;
      a--;b--;
      Graph[a].push_back(edge(b,f));
      Graph[b].push_back(edge(a,f));
    }
    for(int i=0;i<=c;i++){
      for(int j=0;j<MAX_V;j++){
	min_cost[i][j] = INF;
      }
    }
    for(int i=0;i<=c;i++){
      Dijkstra(s,i);
    }

    cout<<min_cost[c][d]<<endl;
    
    for(int i=0;i<MAX_V;i++) Graph[i].clear();
  }
  return 0;
}

C++: // 2010/12/29 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int c, n, m, s, d;
		cin >> c >> n >> m >> s >> d;
		if(c==0&&n==0&&m==0&&s==0&&d==0)
			break;

		int wgt[102][102];
		int hlf[102][102];
		for(int i=1; i<=n; i++)
			for(int j=1; j<=n; j++)
				if(i==j){
					wgt[i][j] = 0;
					hlf[i][j] = 20000;
				}
				else{
					wgt[i][j] = 20000;
					hlf[i][j] = 20000;
				}

		for(int i=0; i<m; i++){
			int a, b, f;
			cin >> a >> b >> f;
			wgt[a][b] = f;
			wgt[b][a] = f;
			hlf[a][b] = f/2;
			hlf[b][a] = f/2;
		}

		int djk[12][102];
		bool flg[12][102];
		for(int i=1; i<=n; i++){
			djk[c][i] = wgt[s][i];
			flg[c][i] = false;
			djk[c-1][i] = hlf[s][i];
			flg[c-1][i] = false;
		}
		for(int j=c-2; j>=0; j--)
			for(int i=1; i<=n; i++){
				djk[j][i] = 20000;
				flg[j][i] = false;
			}

		while(true){
			int j_min = 11;
			int i_min = 0;
			int w_min = 2000000;
			for(int j=0; j<=c; j++)
				for(int i=1; i<=n; i++)
					if((!flg[j][i])&&(djk[j][i]<w_min)){
						j_min = j;
						i_min = i;
						w_min = djk[j][i];
					}

			flg[j_min][i_min] = true;
			if(i_min==d){
				cout << djk[j_min][i_min] << endl;
				break;
			}

			for(int i=1; i<=n; i++)
				if(!flg[j_min][i])
					if(wgt[i_min][i]!=20000)
						if(djk[j_min][i]>djk[j_min][i_min]+wgt[i_min][i])
							djk[j_min][i] = djk[j_min][i_min]+wgt[i_min][i];
			if(j_min!=0)
				for(int i=1; i<=n; i++)
					if(!flg[j_min-1][i])
						if(hlf[i_min][i]!=20000)
							if(djk[j_min-1][i]>djk[j_min][i_min]+hlf[i_min][i])
								djk[j_min-1][i] = djk[j_min][i_min]+hlf[i_min][i];
		}
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
typedef pair<int, int> Pii;
typedef pair<int, Pii> Pip;
typedef vector<int> Vi;
const int INF = (1<<25);
const int MAX_V = 101;
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

struct edge {
  int to, cost;
  edge(int _to, int _cost) {
    to = _to; cost = _cost;
  }
};

int dij(int s, int c, int g) {
  priority_queue<Pip, vector<Pip>, greater<Pip> > q;

  int d[11][101];
  for(int i=0; i<11; i++) {
    for(int j=0; j<101; j++) {
      d[i][j] = INF;
    }
  }

  d[c][s] = 0;
  q.push(Pip(0, Pii(s, c)));

  int result = INF;
  while( !q.empty() ) {
    Pip p = q.top(); q.pop();
    int now_cost = p.fr;
    int v = p.sc.fr;
    int c = p.sc.sc;

    if( v == g ) {
      result = now_cost;
      break;
    }

    for(int i=0; i<G[v].size(); i++) {
      edge e = G[v][i];

      int next_cost = d[c][v] + e.cost;
      if( next_cost < d[c][e.to] ) {
	d[c][e.to] = next_cost;
      }
      if( c ) {
	next_cost = d[c][v] + e.cost/2;
	if( next_cost < d[c-1][e.to] ) {
	  d[c-1][e.to] = next_cost;
	  q.push(Pip(next_cost, Pii(e.to, c-1)));
	}
      }
    }
  }
  return result;
}

int main() {
  int c, n, m, s, g;
  while( cin >> c >> n >> m >> s >> g, c || n || m || s || g ) {
    init(n);
    s--; g--;
    for(int i=0; i<m; i++) {
      int u, v, cost;
      cin >> u >> v >> cost;
      u--; v--;
      G[u].pb(edge(v, cost));
      G[v].pb(edge(u, cost));
    }
    int ans = dij(s, c, g);
    cout << ans << endl;
  }
}