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<queue>
#include<vector>
using namespace std;
#define MAX 100000
#define MAX_NODE_ID 101
#define MAX_TICKET 11
class Node{
public:
	int id;
	int cost;
	int ticket;
	Node(int i,int c,int t){
		id=i;
		cost=c;
		ticket=t;
	}
	bool operator < (const Node &o) const{
		return cost > o.cost;
	}
};
typedef priority_queue<Node> PQ;
int table[MAX_NODE_ID][MAX_NODE_ID];
bool visited[MAX_NODE_ID][MAX_TICKET];
int main(){

	for(int c,n,m,s,d;cin>>c>>n>>m>>s>>d&&(c||n||m||s||d);){
		for(int i=0;i<MAX_NODE_ID;i++)for(int j=0;j<MAX_NODE_ID;j++)table[i][j]=MAX;
		for(int i=0;i<MAX_NODE_ID;i++)for(int j=0;j<MAX_TICKET;j++)visited[i][j]=false;
		for(int i=0,a,b,f;i<m&&cin>>a>>b>>f;i++){
			table[a][b]=f;
			table[b][a]=f;
//			cout<<"table["<<a<<"]["<<b<<"]"<<table[a][b]<<endl;
//			cout<<"table["<<b<<"]["<<a<<"]"<<table[b][a]<<endl;
		}
		PQ pq;
		Node start(s,0,c);
		pq.push(start);
		while(!pq.empty()){
			int current_node=pq.top().id;
			int current_cost=pq.top().cost;
			int current_ticket=pq.top().ticket;
//			cout<<"current:"<<current_node<<endl;
			if(current_node==d)break;
			if(visited[current_node][current_ticket]);
			else{
				for(int i=1;i<=n;i++){
					if(current_node==i)continue;
					if(table[current_node][i]==MAX)continue;
	//				cout<<"["<<current_node<<"]["<<i<<"]"<<"cost:"<<table[current_node][i]<<endl;
					Node node1(i,current_cost+table[current_node][i],current_ticket);
					pq.push(node1);
					visited[current_node][current_ticket]=true;
					if(current_ticket>0){
						Node node2(i,current_cost+(table[current_node][i]/2),current_ticket-1);
						pq.push(node2);
						visited[current_node][current_ticket-1]=true;
					}
				}
			}
			pq.pop();
		}
		cout<<pq.top().cost<<endl;
	}


	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define MAX 1000
#define INF 9999999

int c,n,m,s,d,a,b,f,cost[MAX+1][MAX+1],dd[MAX+1][MAX+1];
bool used[MAX+1][MAX+1];

int dijkstra(int s,int d,int c){
    fill(dd[0],dd[MAX],INF);
    fill(used[0],used[MAX],false);
    
    dd[c][s-1] = 0;
    while(true){
        int Mini = -1 , Minj;
        
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j <= c ; j++){
                if((dd[j][i] < dd[Minj][Mini] || Mini == -1)&&!used[j][i]){
                    Mini = i;
                    Minj = j;
                }
            }
        }
        
        if(Mini == -1) break;
        used[Minj][Mini] = true;
        
        for(int i = 0 ; i < n ; i++){
            dd[Minj][i] = min(dd[Minj][i],dd[Minj][Mini]+cost[Mini][i]);
            if(Minj > 0) dd[Minj-1][i] = min(dd[Minj-1][i],dd[Minj][Mini]+cost[Mini][i]/2);
        }
    }
    
    int res = INF;
    for(int i = 0 ; i <= c ; i++){
        res = min(res,dd[i][d-1]);
    }
    
    return res;
}

int main(){
    while(cin >> c >> n >> m >> s >> d, c+n+m+s+d){
        fill(cost[0],cost[MAX],INF);
        for(int i = 0 ; i < m ; i++){
            cin >> a >> b >> f;
            cost[a-1][b-1] = f;
            cost[b-1][a-1] = f;
        }
        
        cout << dijkstra(s,d,c) << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<queue>
#include<vector>

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)
#define INF 1000000000

struct edge {int cost, to; };

typedef pair<int, pair<int, int> > P; // cost, vertex, chicket
typedef pair<int, int> Pint; //

int c, n, m, s, d;
int dist[110][15];

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

        vector<edge> g[110];
        REP(i, m) {
            int a, b, f;
            cin >> a >> b >> f;
            
            edge e;
            e.to = b-1;
            e.cost = f;
            g[a-1].push_back(e);
            
            edge e2;
            e2.to = a-1;
            e2.cost = f;
            g[b-1].push_back(e2);
        }

        REP(i, n) {
            REP(j, c+1) {
                dist[i][j] = INF;
            }
        }
        dist[s-1][c] = 0;

        P p=pair<int, Pint>(0, Pint(s-1, c));
        priority_queue<P, vector<P>, greater<P> > que;
        que.push(p);

        while(!que.empty()) {
            P p = que.top();
            que.pop();

            int v = p.second.first;
            int ckt = p.second.second;
            if(dist[v][ckt] < p.first) continue;

            REP(i, g[v].size()) {
                int to = g[v][i].to;
                int cost = g[v][i].cost;
                // don't use chicket
                if (dist[to][ckt] > dist[v][ckt] + cost){
                    dist[to][ckt] = dist[v][ckt] + cost;
                    P p = pair<int, Pint>(dist[v][ckt] + cost, Pint(to, ckt));
                    que.push(p);
                }

                // use chicket
                if (ckt >= 1) {
                    if (dist[to][ckt-1] > dist[v][ckt] + cost/2){
                        dist[to][ckt-1] = dist[v][ckt] + cost/2;
                        P p = pair<int, Pint>(dist[v][ckt] + cost/2, Pint(to, ckt-1));
                        que.push(p);
                    }
                }
            }
        }
        
        int output = INF;
        REP(i, c+1) {
            output = min(output, dist[d-1][i]);
        }

        cout << output << endl;
    }
}