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 <queue>
#include <vector>
#include <cstdio>

#define reep(i,n,m) for(int i=(n);i<(m);i++)
#define rep(i,n) reep(i,0,n)

using namespace std;

class Edge{
public:
    int to;
    int cost;
    Edge(int to,int cost):to(to),cost(cost){}
};

class Node{
public:
    int distance;
    int num;
    int ticket;
    Node(){}
    Node(int distance, int num,int ticket):distance(distance),num(num),ticket(ticket){}
    bool operator<(const Node &b)const{
        return distance > b.distance;
    }
};

vector<Edge> edge[101];
bool flg[101][11];

void init(){
    rep(i,101){
        edge[i].clear();
        rep(k,11){
            flg[i][k] = 0;
        }
    }
}

int main(){
    int c,n,m,s,d;
    while(cin >> c >> n >> m >> s >> d,!m==0){
        init();
        rep(i,m){
            int a,b,c;
            cin >> a >> b >> c;
            edge[a].push_back(Edge(b,c));
            edge[b].push_back(Edge(a,c));
        }
        priority_queue<Node> Q;
        Q.push(Node(0,s,0));
        int ans = 1000000;
        while(!Q.empty()){
            Node node = Q.top();Q.pop();
            if(flg[node.num][node.ticket]){
                continue;
            }
            flg[node.num][node.ticket] = true;
            //printf("num->%d cost->%d ticket->%d\n",node.num,node.distance,node.ticket);
            if(node.num == d){
                ans = min(ans,node.distance);
            }

            rep(i,edge[node.num].size()){
                Edge e = edge[node.num][i];
                int cost = node.distance + e.cost;
                Q.push(Node(cost,e.to,node.ticket));
                if(node.ticket < c){
                    int cost = node.distance + e.cost/2;
                    Q.push(Node(cost,e.to,node.ticket+1));
                }
            }
        }
        cout << ans << endl;
    }
}

C++: #include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
};

/** Problem0212 : Highway Express Bus **/
struct edge{
	int from, to, cost;
	edge(int f, int t, int c):from(f), to(t), cost(c){}
	edge(){}
};
vector<edge> G;

int main()
{
	int C, N, M, S, D;
	while (cin>>C>>N>>M>>S>>D, C) {
		S--, D--;
		G.clear();
		
		rep(i, M) {
			int a, b, f;
			cin>>a>>b>>f;
			a--, b--;
			G.push_back(edge(a, b, f));
			G.push_back(edge(b, a, f));
		}
		
		int d[100][11];
		fill(d[0], d[0]+1000, INF);
		for (int i=0; i<C+1; i++) d[S][i]=0;
		
		while (true) {
			bool update=false;
			
			for (int i=0; i<G.size(); i++) {
				edge e = G[i];
				for (int j=0; j<=C; j++) {
					if (d[e.to][j] > d[e.from][j] + e.cost) {
						d[e.to][j] = d[e.from][j] + e.cost;
						update = true;
					}
					
					
					if (j<=C) {
						if (d[e.to][j+1] > d[e.from][j]+e.cost/2) {
							d[e.to][j+1] = d[e.from][j]+e.cost/2;
							update = true;
						}
					}
				}
			}
			
			if (!update) break;
		}
		
		int ans = INF;
		for (int i=0; i<C+1; i++) {
			ans = min(ans, d[D][i]);
		}
		cout << ans << endl;
	}
}

C++: #include <cstdio>
#include <iostream>
#include <string>
#include <queue>
#define INF (1<<21)
using namespace std;

class State{
public:
  int n,cost,c,f;
  State(int n = 0,int cost = 0, int c = 0,int f = 0):n(n),cost(cost),c(c),f(f){}
  bool operator < (const State &s) const{ return cost > s.cost;}
};

int main(){
  int i,j;
  while(1){
    int G[101][101],c,n,m,s,t;
    State d[101][11];
    priority_queue<State> PQ;

    cin >> c >> n >> m >> s >> t;
    if(c == 0 && n == 0 && m == 0 && s == 0 && t == 0) break;

    for(i=0;i<=n;i++){
      for(j=0;j<=n;j++) G[i][j] = INF;
      for(j=0;j<=c;j++){
	d[i][j].cost = INF;
	d[i][j].n = i;
	d[i][j].c = j;
	d[i][j].f = 0;
      }
    }

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

    d[s][c].cost = 0;
    State p = d[s][c];
    PQ.push(p);

    while(!PQ.empty()){
      p = PQ.top();
      PQ.pop();
      d[p.n][p.c].f = 1;

      for(i=0;i<=n;i++){
	if(d[i][p.c].f == 0 && G[p.n][i] + p.cost < d[i][p.c].cost){
	  d[i][p.c].cost = G[p.n][i] + p.cost;
	  PQ.push(d[i][p.c]);
	}
	if(p.c > 0 && G[p.n][i] != INF && d[i][p.c-1].f == 0 && G[p.n][i] / 2 + p.cost < d[i][p.c-1].cost){
	  d[i][p.c-1].cost = G[p.n][i] / 2 + p.cost;
	  PQ.push(d[i][p.c-1]);
	}
      }
    }

    int min = INF;
    for(i=0;i<=c;i++){
      if(min > d[t][i].cost) min = d[t][i].cost;
    }
    cout << min << endl;

  }
  return 0;
}

//0212