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 <bits/stdc++.h>

using namespace std;

struct Node {
    Node(int s, int t, int c) : s(s), t(t), c(c) {}

    int s, t, c;

    bool operator<(const Node &rhs) const {
        return c > rhs.c;
    }
};

int main() {
    int c, n, m, s, d;
    while (cin >> c >> n >> m >> s >> d && n) {
        --s, --d;
        vector<vector<Node> > g(n);

        for (int i = 0; i < m; i++) {
            int a, b, c;
            cin >> a >> b >> c;
            --a, --b;
            g[a].push_back(Node(b, 0, c));
            g[b].push_back(Node(a, 0, c));
            g[a].push_back(Node(b, 1, c / 2));
            g[b].push_back(Node(a, 1, c / 2));
        }
        priority_queue<Node> Q;
        Q.push(Node(s, c, 0));
        bool flg[111][11] = {};
        while (Q.size()) {
            Node q = Q.top();
            Q.pop();
            if (flg[q.s][q.t]) continue;
            if (q.s == d) {
                cout << q.c << endl;
                break;
            }
            flg[q.s][q.t] = true;
            for (auto e : g[q.s]) {
                if (q.t >= e.t) {
                    Q.push(Node(e.s, q.t - e.t, q.c + e.c));
                }
            }
        }
    }
}

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

using namespace std;

struct edge{ int to, cost; };
typedef pair<int, int> P;
const int INF = INT_MAX / 4;

int V;
vector<edge> G[100];
int D[100];
int pre[100];

int c, n, m, s, d;

void dijkstra(int s)
{
	priority_queue<P, vector<P>, greater<P> > que;
	fill(D, D + 100, INF);
	fill(pre, pre + 100, -1);
	D[s] = 0;
	que.push(P(0, s));

	while (!que.empty())
	{
		P p = que.top(); que.pop();
		int v = p.second;
		if (D[v] < p.first) continue;
		for (int i = 0; i < G[v].size(); i++)
		{
			edge e = G[v][i];
			if(D[e.to] > D[v] + e.cost)
			{
				D[e.to] = D[v] + e.cost;
				pre[e.to] = v;
				que.push(P(D[e.to], e.to));
			}
		}
	}
}

int solve()
{
	dijkstra(s - 1);
	vector<int> vec;
	for (int t = d - 1; pre[t] != -1 ; t = pre[t])
	{
		for (int i = 0; i < G[t].size(); i++)
		{
			if(pre[t] == G[t][i].to)
			{
				vec.push_back(G[t][i].cost);
				break;
			}
		}
	}
	sort(vec.begin(), vec.end(), greater<int>());
	for (int i = 0; i < c && i < vec.size(); i++)
	{
		vec[i] = vec[i] / 2;
	}
	return accumulate(vec.begin(), vec.end(), 0);
}

int main()
{
	while (cin >> c >> n >> m >> s >> d && c && n && m && s && d)
	{
		for (int i = 0; i < 100; i++)
		{
			G[i] = vector<edge>();
		}
		for (int i = 0; i < m; i++)
		{
			int a, b, f;
			cin >> a >> b >> f;
			edge e;
			e.to = b - 1;
			e.cost = f;
			G[a - 1].push_back(e);
			e.to = a - 1;
			e.cost = f;
			G[b - 1].push_back(e);
		}
		cout << solve() << endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<queue>
#include<functional>
#include<algorithm>
using namespace std;
struct S{int i,c,r;};
struct C:binary_function<S,S,int>{int operator()(S l,S r){return l.c>r.c;}};
int main()
{
	int c,n,m,s,d,i,a,b,f,_=0x3f3f3f3f;
	int g[100][100];
	int x[100][11];
	while(scanf("%d%d%d%d%d",&c,&n,&m,&s,&d),c)
	{
		memset(g,63,sizeof(g));
		memset(x,63,sizeof(x));
		for(i=0;i<m;++i)
		{
			scanf("%d%d%d",&a,&b,&f);
			g[a-1][b-1]=g[b-1][a-1]=f;
		}
		S p,t;
		p.c=0;
		p.r=c;
		p.i=s-1;
		priority_queue<S,vector<S>,C>q;
		q.push(p);
		while(!q.empty())
		{
			p=q.top();q.pop();
			if(x[p.i][p.r]<=p.c)continue;
			x[p.i][p.r]=p.c;
			for(i=0;i<n;++i)
			{
				if(g[p.i][i]==_)continue;
				if(p.r)
				{
					t=p;
					t.r--;
					t.c+=g[t.i][i]/2;
					t.i=i;
					q.push(t);
				}
				t=p;
				t.c+=g[t.i][i];
				t.i=i;
				q.push(t);
			}
		}
		printf("%d\n",*min_element(x[d-1],x[d]));
	}
	return 0;
}

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

using namespace std;

#define MAX_N 101
#define INF 1 << 28

struct edge_t {
    int from, to, cost;
    edge_t(int from=0, int to=0, int cost=0) :
        from(from), to(to), cost(cost) {}
};

struct state_t {
    int city;   // 現在地
    int coupon; // 残り割引券枚数
    int cost;   // 現在地までにかかった金額
    state_t(int city=0, int coupon=0, int cost=0) :
        city(city), coupon(coupon), cost(cost) {}
    bool operator>(const state_t &o) const {
        return cost == o.cost ? coupon < o.coupon : cost > o.cost;
    }
    bool operator<(const state_t &o) const {
        return cost == o.cost ? coupon > o.coupon : cost < o.cost;
    }
};

int c, n, m, s, d;
vector<edge_t> graph[MAX_N];

int dijkstra() {
    int cost[n+1][c+1];
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= c; j++)
            cost[i][j] = INF;

    priority_queue<state_t, vector<state_t>, greater<state_t> > q;

    cost[s][c] = 0;

    q.push(state_t(s, c, 0));

    while (!q.empty()) {
        state_t p = q.top(); q.pop();

        for (int i = 0; i < graph[p.city].size(); i++) {
            edge_t e = graph[p.city][i];

            // クーポン券を使わないとき
            if (cost[e.to][p.coupon] > cost[e.from][p.coupon] + e.cost) {
                cost[e.to][p.coupon] = cost[e.from][p.coupon] + e.cost;
                q.push(state_t(e.to, p.coupon, cost[e.to][p.coupon]));
            }

            // クーポン券を使うとき
            if (p.coupon > 0) {
                if (cost[e.to][p.coupon-1] > cost[e.from][p.coupon] + e.cost / 2) {
                    cost[e.to][p.coupon-1] = cost[e.from][p.coupon] + e.cost / 2;
                    q.push(state_t(e.to, p.coupon-1, cost[e.to][p.coupon-1]));
                }
            }
        }
    }

    int min_cost = INF;
    for (int i = 0; i <= c; i++) 
        min_cost = min(min_cost, cost[d][i]);
    return min_cost;
}

int main() {
    while (cin >> c >> n >> m >> s >> d) {
        if (c == 0 && n == 0 && m == 0 && s == 0 && d == 0) break;
        for (int i = 0; i <= n; i++) graph[i].clear();
        for (int i = 0; i < m; i++) {
            int a, b, f; cin >> a >> b >> f;
            graph[a].push_back(edge_t(a, b, f));
            graph[b].push_back(edge_t(b, a, f));
        }
        cout << dijkstra() << endl;
    }
    return 0;
}