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 <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <cstring>
#include <string>
#include <sstream>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<int> > table;

int n;
const int INF = (int)1e7;
const int N = 100;
const int C = 11;
table cost(N);
vector<vector<bool> > used(11);

int dijkstra(int, int, int);

int main(void){
    rep(i, N) cost[i].resize(N);
    rep(i, C) used[i].resize(N);

    for(int c, m, s, g; cin >> c >> n >> m >> s >> g, n; cout << dijkstra(s, g, c) << endl){
        rep(i, N) fill(ALL(cost[i]), INF);
        rep(i, C) fill(ALL(used[i]), false);

        while(m --){
            int a, b, f; cin >> a >> b >> f;
            
            cost[a - 1][b - 1] = cost[b - 1][a - 1] = f;
        }
    }
    
    return 0;
}

int dijkstra(int s, int g, int c){
    table d(c + 1);
    rep(i, c + 1) d[i].resize(n), fill(ALL(d[i]), INF);
    
    d[c][s - 1] = 0;

    while(1){
        int vn = -1, vc = -1;

        rep(i, c + 1) rep(j, n) if(!used[i][j] && (vc == -1 || d[i][j] < d[vc][vn])) vc = i, vn = j;

        if(vc == -1) break;
        used[vc][vn] = true;

        rep(u, n){
            d[vc][u] = min(d[vc][u], d[vc][vn] + cost[vn][u]);
            if(vc) d[vc - 1][u] = min(d[vc - 1][u], d[vc][vn] + cost[vn][u] / 2);
        }
    }

    return d[0][g - 1];
}

C++: #include<queue>
#include<cstdio>
#include<algorithm>

#define	mp	make_pair

using namespace std;

typedef	pair<int,int>	pii;

const int inf=1<<29;
int adj[100][100],memo[100][11];
bool visited[100][11];

int main(){
	for(int c,n,m,src,dst;scanf("%d%d%d%d%d",&c,&n,&m,&src,&dst),c;){
		src--,dst--;
		for(int i=0;i<n;i++)for(int j=0;j<n;j++)	adj[i][j]=(i==j?0:inf);
		for(int i=0;i<n;i++)for(int j=0;j<=c;j++)	memo[i][j]=inf,visited[i][j]=false;
		for(int i=0;i<m;i++){
			int a,b,fee;	scanf("%d%d%d",&a,&b,&fee);
			a--,b--;
			adj[a][b]=adj[b][a]=fee;
		}

		memo[src][0]=0;
		priority_queue< pair<int,pii> > pq;	pq.push(mp(0,mp(src,0)));
		while(!pq.empty()){
			pair<int,pii> a=pq.top();	pq.pop();
			int fee=-a.first;
			int u=a.second.first;
			int tic=a.second.second;
			if(u==dst)	break;

			if(visited[u][tic])	continue;
			visited[u][tic]=true;

			for(int v=0;v<n;v++){
				if(!visited[v][tic] && fee+adj[u][v]<memo[v][tic]){
					memo[v][tic]=fee+adj[u][v];
					pq.push(mp(-memo[v][tic],mp(v,tic)));
				}
				if(tic<c && !visited[v][tic+1] && fee+adj[u][v]/2<memo[v][tic+1]){
					memo[v][tic+1]=fee+adj[u][v]/2;
					pq.push(mp(-memo[v][tic+1],mp(v,tic+1)));
				}
			}
		}

		int feemin=inf;
		for(int i=0;i<=c;i++)	feemin=min(feemin,memo[dst][i]);
		printf("%d\n",feemin);
	}

	return 0;
}

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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<28

using namespace std;
typedef pair<int,int> P;


struct edge
{
	int to;
	int cost;

	edge(int to,int cost) : to(to),cost(cost) {}
};

int d[101][11];
vector<edge> G[101];

void dijkstra(int s,int n,int ticket)
{
	priority_queue<P,vector<P>,greater<P> > que;
	rep(i,n) d[i][ticket] = INF;
	d[s][ticket] = 0;
	que.push(P(0,s));

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

		int v = p.second;
		if(d[v][ticket] < p.first) continue;

		rep(i,G[v].size())
		{
			edge e = G[v][i];
			int temp;

			if(ticket == 0)
			{
				temp = d[v][ticket] + e.cost;
			}
			else
			{
				temp =  min(d[v][ticket]+e.cost,d[v][ticket-1]+e.cost/2);
			}

			if(d[e.to][ticket] > temp)
			{
				d[e.to][ticket] = temp;
				que.push(P(d[e.to][ticket],e.to));
			}
		}
	}
}

int main()
{
	int c,n,m,s,t;
	while(cin >> c >> n >> m >> s >> t)
	{
		if(c == 0 && n == 0 && m == 0 && s == 0 && t == 0) break;
		
		s--;
		t--;
		rep(i,100) G[i].clear();

		rep(i,m)
		{
			int a,b,cost;
			cin >> a >> b >> cost;
			a--;
			b--;

			edge e(b,cost);
			G[a].push_back(e);

			edge e2(a,cost);
			G[b].push_back(e2);
		}
		
		rep(i,c+1) dijkstra(s,n,i);

		cout <<  d[t][c] << endl;
	}

	return 0;
}

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];

int c,n,m,s,d;

int solve(){

    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));
            }
        }
    }
    return solve();
}



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

int main(){

    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));
        }
        cout << solve() << endl;
    }
}