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]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)
					}
				}
			}
		}
		runtime.GC()
	}
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int c,n,m,s,d;
	while(cin>>c>>n>>m>>s>>d,n){
		s--;d--;
		int cost[110][110];
		rep(i,110)rep(j,110)cost[i][j]=inf;
		while(m--){
			int a,b,e;
			cin>>a>>b>>e;
			a--;b--;
			cost[a][b]=cost[b][a]=e;
		}
		int dp[110][11];
		int used[110]={0};
		rep(i,110)rep(j,11)dp[i][j]=inf;
		rep(i,11)dp[s][i]=0;
		while(1){
			int v=-1;
			rep(i,n)if(!used[i]&&(v==-1||dp[v][0]>dp[i][0]))v=i;
			if(v==-1)break;
			used[v]=true;
			rep(i,n)for(int j=c;j>=0;j--){
				dp[i][j]=min(dp[i][j],dp[v][j]+cost[v][i]);
				dp[i][j+1]=min(dp[i][j+1],dp[v][j]+cost[v][i]/2);
			}
		//rep(i,6){rep(j,3)cout<<" "<<dp[i][j];cout<<endl;}
		//cout<<endl;
		}
		//rep(i,6){rep(j,3)cout<<" "<<dp[i][j];cout<<endl;}
		cout<<dp[d][c]<<endl;
	}
}

C++: #include <iostream>
#include <algorithm>
using namespace std;

#define MAX 100
int INF = 1000000;
int G[MAX][MAX];
int c, n, m, s, d, a, b, f;

int dijkstra(){
    int D[MAX][11];
    bool visited[MAX][11];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= c; j++) {
            D[i][j] = INF;
            visited[i][j] = false;
        }
    }
    D[s][c] = 0;
    while (true) {
        int u = 0, w = 0, minv = INF;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= c; j++) {
                if (!visited[i][j] && minv > D[i][j]) {
                    minv = D[i][j];
                    u = i;
                    w = j;
                }
            }
        }
        if (minv == INF) {
            break;
        }
        visited[u][w] = true;
        for (int v = 0; v < n; v++) {
            if (G[u][v] == INF) {
                continue;
            }
            D[v][w] = min(D[v][w], D[u][w] + G[u][v]);
            if (w) {
                D[v][w-1] = min(D[v][w-1], D[u][w] + G[u][v] / 2);
            }
        }
    }
    int minv = INF;
    for (int i = 0; i <= c; i++) {
        minv = min(minv, D[d][i]);
    }
    return minv;
}

int main()
{
    while (true) {
        cin >> c >> n >> m >> s >> d;
        if (s == 0 && d == 0) {
            break;
        }
        s--;
        d--;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                G[i][j] = INF;
            }
        }
        for (int i = 0; i < n; i++) {
            cin >> a >> b >> f;
            a--;
            b--;
            G[a][b] = G[b][a] = f;
        }
        cout << dijkstra() << endl;
    }

    return 0;
}

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

using namespace std;
typedef pair<int, int> Pi;
typedef pair<int, Pi> Ti;

int c, n, m, s, d;
vector<vector<Pi>> edge;

int djk(int s, int g) {
	int d[100][11];
	for (int i = 0; i < n; i++)for (int j = 0; j <= c; j++)d[i][j] = 1000000000;
	d[s][c] = 0;
	priority_queue<Ti, vector<Ti>, greater<Ti>> pq;
	pq.push(make_pair(0, make_pair(s, c)));
	while (pq.size()) {
		Ti tmp = pq.top(); pq.pop();
		int N = tmp.second.first, ticket = tmp.second.second;
		if (d[N][ticket] < tmp.first)continue;
		for (int i = 0; i < edge[N].size(); i++) {
			int to = edge[N][i].first, cost = edge[N][i].second;
			if (ticket > 0) {
				if (d[to][ticket - 1] > d[N][ticket] + cost / 2) {
					d[to][ticket - 1] = d[N][ticket] + cost / 2;
					pq.push(make_pair(d[to][ticket - 1], make_pair(to, ticket - 1)));
				}
			}
			else {
				if (d[to][ticket] > d[N][ticket] + cost) {
					d[to][ticket] = d[N][ticket] + cost;
					pq.push(make_pair(d[to][ticket], make_pair(to, ticket)));
				}
			}
		}
	}
	int ans = 1000000000;
	for (int i = 0; i <= c; i++)ans = min(ans, d[g][i]);
	return ans;
}

int main() {
	while (cin >> c >> n >> m >> s >> d, c + n + m + s + d) {
		s--, d--;
		edge.resize(n);

		for (int i = 0; i < m; i++) {
			int a, b, f;
			cin >> a >> b >> f, a--, b--;
			edge[a].push_back(make_pair(b, f));
			edge[b].push_back(make_pair(a, f));
		}
		cout << djk(s, d) << endl;
		edge.clear();
	}
	return 0;
}