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)
		}
		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)
		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 <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;
}

C++: #include <iostream>
#include <algorithm>
#include <queue>
#include <utility>
#include <vector>
#include <functional>

using namespace std;

typedef pair<int, int> P;
const int N = 100, INF = 10e6;
int edge[N][N];

vector<int> dijkstra(int n, int s, int d){
    priority_queue<P> pq;
    vector<int> ret;
    int visited[n], now = d;
    fill(visited, visited + n, 0);
    pq.push(make_pair(1, s));
    visited[s] = 1;
    while(!pq.empty()){
        P t = pq.top();
        pq.pop();
        visited[t.second] = t.first;
        if(t.second == d) break;
        for(int i = 0;i < n;++i){
            if(edge[t.second][i] != INF && !visited[i]){
                pq.push(make_pair(t.first + 1, i));
            }
        }
    }
    while(now != s){
        int m = INF, t = now;
        for(int i = 0;i < n;++i){
            if(visited[i] == visited[now] - 1 && edge[now][i] != INF){
                m = min(m, edge[now][i]);
                t = m == edge[now][i] ? i : t;
            }
        }
        ret.push_back(m);
        now = t;
    }
    return ret;
}

int main(){
    int c, n, m, s, d;
    while(cin >> c >> n >> m >> s >> d, c){
        int a, b, f, res = 0;
        --s; --d;
        for(int i = 0;i < N;++i){
            fill(edge[i], edge[i] + N, INF);
        }
        for(int i = 0;i < m;++i){
            cin >> a >> b >> f;
            --a; --b;
            edge[a][b] = edge[b][a] = f;
        }
        vector<int> r = dijkstra(n, s, d);
        sort(r.begin(), r.end(), greater<int>());
        vector<int>::iterator vit = r.begin();
        for(;vit != r.end();++vit){
            if(c != 0){
                *vit = *vit / 2;
                --c;
            }
            res += *vit;
        }
        cout << res << endl;
    }
    return 0;
}