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
}

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)
		}
		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)
		start := Node{NowPosition: s, DiscountTicketTCount: c, Amount: 0}
		heap.Push(&pq, &start)
		for len(pq) != 0 {
			now := heap.Pop(&pq).(*Node)
			if now.NowPosition == d {
				fmt.Println(now.Amount)
				break
			}
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				heap.Push(&pq, next)
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					heap.Push(&pq, next)
				}
			}
		}
	}
}

C++: #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

typedef int Weight;
struct Edge {
  int cnt;
  int src;
  int dest;
  Weight weight;
  Edge(int cnt, int src, int dest, Weight weight) : cnt(cnt), src(src), dest(dest), weight(weight) {;}
  bool operator<(const Edge &rhs) const {
    return weight > rhs.weight;
  }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int c, n, m, s, d;
bool visit[20][110];

int main() {
  while (scanf("%d %d %d %d %d", &c, &n, &m, &s, &d), c|n|m|s|d) {
    MEMSET(visit, false);
    s--; d--;
    Graph g(n);
    REP(i, m) {
      int f, t, cost;
      scanf("%d %d %d", &f, &t, &cost);
      f--; t--;
      g[f].push_back(Edge(0xdeadbeaf, 0xdeadbeaf, t, cost));
      g[t].push_back(Edge(0xdeadbeaf, 0xdeadbeaf, f, cost));
    }
    priority_queue<Edge> que;
    que.push(Edge(c, 0xdeadbeaf, s, 0));
    while (!que.empty()) {
      Edge e = que.top();
      que.pop();
      if (visit[e.cnt][e.dest]) { continue; }
      visit[e.cnt][e.dest] = true;
      if (e.dest == d) {
        printf("%d\n", e.weight);
        break;
      }
      FORIT(it, g[e.dest]) {
        if (e.cnt != 0) {
          int ncost = e.weight + it->weight / 2;
          que.push(Edge(e.cnt - 1, 0xdeadbeaf, it->dest, ncost));
        }
        int ncost = e.weight + it->weight;
        que.push(Edge(e.cnt, 0xdeadbeaf, it->dest, ncost));
      }
    }
  }
}

C++: #include <iostream>
#include <queue>
#include <algorithm>
#include <cstring>

#define MAX 1000000000
#define Debug(X) debug( __LINE__, X )
template<class T>
void debug( int line, T dbg ){
	std::cout << line << ": " << dbg << std::endl;
}

class State{
public:
	int p, s, c;
	State():p(0), s(0), c(0){}
	State(int P, int S, int C):p(P), s(S), c(C){}
	bool operator < (const State &s) const{
		return c > s.c;
	}
};

int c, n, m, s, d;
int route[101][101];
std::priority_queue<State> que;
bool used[101][11];


int main(){
	while( std::cin >> c >> n >> m >> s >> d, c * n * m * s * d ){
		for( int i = 0; i < 101 * 101; ++i )
			route[i / 101][i % 101] = MAX;
		
		memset( used, 0, sizeof( used ) );
		que = std::priority_queue<State>();

		int tmp[3];
		while( m-- ){
			int cnt = 3;
			while( cnt-- ) std::cin >> tmp[2 - cnt];

			route[tmp[0]][tmp[1]] = tmp[2];
			route[tmp[1]][tmp[0]] = tmp[2];
		}

		que.push(State( c, s, 0 ));

		while( true ){
			State data = que.top(); que.pop();

			if( used[data.s][data.p] )continue;
			used[data.s][data.p] = 1;

			if( data.s == d ){
				std::cout << data.c << std::endl;
				break;
			}

			for( int i = 1; i <= n; ++i ){
				if( i == data.s || route[data.s][i] == MAX )continue;

				if( data.p > 0 )
					que.push( State( data.p - 1, i, data.c + route[data.s][i] / 2 ) );

				que.push( State( data.p, i, data.c + route[data.s][i] ) );				
			}

		}

	}
}

C++: #include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;
#define INF 1e+9
typedef pair<int,int> P;
struct edge{
    int to,cost;
};
int c,n,m,s,end;
vector<edge> G[101];
int d[11][101];

void dijkstra(int s,int a){
    priority_queue<P, vector<P>, greater<P> >Q;
    for(int i=0;i<n;i++)d[a][i] = INF;
    d[a][s] = 0;
    Q.push(P(0,s));
    
    while(!Q.empty()){
        P p=Q.top();
        Q.pop();
        int v = p.second;
        
        if(d[a][v] < p.first)continue;
        for(int i=0;i<G[v].size();i++){
            edge e = G[v][i];
            int dm;
            if(a==0)dm=d[a][v]+e.cost;
            else dm=min(d[a][v]+e.cost,d[a-1][v]+e.cost/2);
            if(d[a][e.to] > dm){
                d[a][e.to] = dm;
                Q.push(P(d[a][e.to],e.to));
            }
        }
    }
}

int main() {
    while(1){
     cin>>c>>n>>m>>s>>end;
     s--;
     end--;
     if(!c)break;
     
     for(int i=0;i<m;i++){
         int a,b,f;
         cin>>a>>b>>f;
         a--;
         b--;
         G[a].push_back((edge){b,f});
         G[b].push_back((edge){a,f});
     }
     int ans = INF;
     for(int i=0;i<=c;i++){
         dijkstra(s,i);
	 }
        
     cout<<d[c][end]<<endl;
     
     for(int i=0;i<100;i++)G[i].clear();
	}
	return 0;
}