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 <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;

#define MAX 110
#define INF (1<<29)
typedef pair<int, int> P;
typedef pair<int, P> P2;

struct edge{
  int to, cost;
};

vector<edge> G[MAX];
int V[MAX][11];
int ticket, n, m, s, d;

int dijkstra(){
  for(int i = 0 ; i < n ; i++)
    for(int j = 0 ; j < 11 ; j++) V[i][j] = INF;
  
  priority_queue<P2, vector<P2>, greater<P2> > que;
  
  que.push(P2(0, P(s, 0)));
  V[s][0] = 0;
  
  while(!que.empty()){
    P2 q = que.top(); que.pop();
    int v = q.second.first;
    int cnt = q.second.second;
    if(V[v][cnt] < q.first) continue;
    
    for(int i = 0 ; i < G[v].size() ; i++){
      edge e = G[v][i];
      if(V[e.to][cnt] > V[v][cnt] + e.cost){
	V[e.to][cnt] = V[v][cnt] + e.cost;
	que.push(P2(V[e.to][cnt], P(e.to, cnt)));
      }
      if(cnt >= ticket) continue;
      
      if(V[e.to][cnt+1] > V[v][cnt] + e.cost/2){
	V[e.to][cnt+1] = V[v][cnt] + e.cost/2;
	que.push(P2(V[e.to][cnt+1], P(e.to, cnt+1)));
      }
    }
  }
  int ret = INF;
  for(int i = 0 ; i <= ticket ; i++){
    ret = min(ret, V[d][i]);
  }
  return ret;
}

int main(){
  while(cin >> ticket >> n >> m >> s >> d){
    if(!ticket && !n && !m && !s && !d) break;
    s--, d--;    
    for(int i = 0 ; i < n ; i++) G[i].clear();
    int from, to, cost;
    for(int i = 0 ; i < m ; i++){
      cin >> from >> to >> cost;
      from--, to--;
      edge e;
      //無向グラフ
      e.to = to, e.cost = cost;
      G[from].push_back(e);
      e.to = from; 
      G[to].push_back(e);
    }
    cout << dijkstra() << endl;
  }
  return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

struct Edge {
	int v, f, c;
	bool operator > (const Edge& e) const { return f > e.f; }
};

int c, n, m, s, d;
vector< vector< Edge > > edges;

int cost[111][11];

int djk() {
	for_(i,0,111) for_(j,0,11) cost[i][j] = (int)1e9;
	
	priority_queue< Edge, vector< Edge >, greater< Edge > > que;
	que.push(Edge{s, 0, c});
	cost[s][c] = 0;
	
	while (!que.empty()) {
		Edge e = que.top(); que.pop();
		
		for (Edge& ei : edges[e.v]) {
			if (cost[ei.v][e.c] > e.f + ei.f) {
				cost[ei.v][e.c] = e.f + ei.f;
				que.push(Edge{ei.v, e.f + ei.f, e.c});
			}
			
			if (e.c > 0 && cost[ei.v][e.c - 1] > e.f + ei.f / 2) {
				cost[ei.v][e.c - 1] = e.f + ei.f / 2;
				que.push(Edge{ei.v, e.f + ei.f / 2, e.c - 1});
			}
		}
	}
	
	int ans = (int)1e9;
	for_(i,0,11) ans = min(ans, cost[d][i]);
	
	return ans;
}

int main() {
	while (cin >> c >> n >> m >> s >> d, n) {
		--s; --d;
		
		edges.assign(n, vector< Edge >());
		
		for_(i,0,m) {
			int a, b, f;
			cin >> a >> b >> f;
			--a; --b;
			edges[a].push_back(Edge{b, f, 0});
			edges[b].push_back(Edge{a, f, 0});
		}
		
		cout << djk() << endl;
	}
}

C++: #include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)

#define MP       make_pair
#define PB       push_back
#define ALL(x)   (x).begin(),(x).end()

const int INF = 1<<29;
const double EPS = 1e-9;
double zero(double d){
  return d < EPS ? 0.0 : d;
}

typedef long long LL;
typedef pair<int,int> P;


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(7);

  int c,n,m,s,d;
  while( cin >> c >> n >> m >> s >> d , c ){

    int dis[11][101];
    bool used[11][101];
    int cost[101][101];

    REP(i,11){
      fill( dis[i], dis[i]+101, INF );
      fill( used[i], used[i]+101, false );
    }
    dis[0][s] = 0;

    REP(i,101){
      fill( cost[i], cost[i]+101, INF );
      cost[i][i] = 0;
    }

    REP(_t,m){
      int a,b,f;
      cin >> a >> b >> f;
      cost[a][b] = cost[b][a] = f;
    }


    while(true){

      // pick minimum distance in unused
      int mini=-1, minj=0;
      REP(i,c+1){
	REP(j,n+1){
	  if( ! used[i][j] ){
	    if( mini==-1 || dis[mini][minj] > dis[i][j] ){
	      mini = i;
	      minj = j;
	    }
	  }
	}
      }

      if( mini == -1)	break;
      used[mini][minj] = true;

      REP(i,m+1){
	dis[mini][i] = min( dis[mini][i], dis[mini][minj] + cost[minj][i] );
	if( mini + 1 <= c )
	  dis[mini+1][i] = min( dis[mini+1][i], dis[mini][minj] + cost[minj][i]/2 );	  
      }
    }

    int res=INF;
    REP(i,c+1)
      res = min( res, dis[i][d] );

    cout << res << endl;
  }

  return 0;
}