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;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int C, N, M, S, D;

vector<P> G[200];
int d[200][20];
priority_queue<P, std::vector<P>, std::greater<P>> pq;

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    while(true){
        std::cin >> C >> N >> M >> S >> D;

        if(C == 0){return 0;}
        
        for(int i=0;i<N+1;++i){
            G[i].clear();
        }
    
        for(int i=0;i<M;++i){
            int A, B, F;
            std::cin >> A >> B >> F;

            G[A].emplace_back(B, F, -1);
            G[B].emplace_back(A, F, -1);        
        }

        fill(&d[0][0], &d[0][0] + 200 * 20, 1001001001);
        d[S][0] = 0;
        pq.emplace(0, S, 0);

        while(!pq.empty()){
            int c, u, uu;
            tie(c, u, uu) = pq.top();
            pq.pop();

            if(d[u][uu] < c){continue;}
        
            for(P& p : G[u]){
            
                int v, c2;
                tie(v, c2, ignore) = p;

                // std::cout << u << " -> " << v << ", " << uu << ", " << d[v][uu+1] << ", " << d[u][uu] << ", " << (c2 / 2) << std::endl;
            
                if(d[v][uu] > d[u][uu] + c2){
                    // std::cout << "?" << u << " -> " << v << ", " << uu << ", " << d[v][uu+1] << ", " << d[u][uu] << ", " << (c2 / 2) << std::endl;
                    d[v][uu] = d[u][uu] + c2;
                    pq.emplace(d[v][uu], v, uu);
                }
                if(uu + 1 <= C && d[v][uu+1] > d[u][uu] + c2 / 2){
                    // std::cout << "!" << u << " -> " << v << ", " << uu << ", " << d[v][uu+1] << ", " << d[u][uu] << ", " << (c2 / 2) << std::endl;
                    d[v][uu+1] = d[u][uu] + c2 / 2;
                    pq.emplace(d[v][uu+1], v, uu+1);
                }
            }
        }

        int mn = 1001001001;
        for(int i=0;i<=C;++i){
            mn = min(mn, d[D][i]);
        }

        std::cout << mn << std::endl;
    }
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef pair<int,int> pii;
typedef pair<int,pii> pip;

class Dijkstra{
private:
    struct edge {int to,cost;};
    vector<vector<edge> > g;
    int n;

public:
    Dijkstra(int size){
        g.resize(size);
        n = size;
    }
    vector<vector<int> > dist;
    void add(int a, int b, int c){
        edge e1 = {b,c}, e2 = {a,c};
        g[a].push_back(e1);
        g[b].push_back(e2);
    }
    int calc(int s,int t,int ma){
        priority_queue<pip,vector<pip>,greater<pip> > q;
        int n = g.size();
        dist = vector<vector<int> > (n, vector<int>(ma+1,1e9));
        dist[s][0] = 0;
        q.push(pip(0,pii(s,0)));
        while(!q.empty()){
            pip p = q.top();
            q.pop();
            int c = p.first;
            pii node = p.second;
            if(dist[node.first][node.second] < c)continue;
            rep(i,g[node.first].size()){
                edge e = g[node.first][i];
                if(dist[e.to][node.second] > dist[node.first][node.second] + e.cost){
                    dist[e.to][node.second] = dist[node.first][node.second] + e.cost;
                    q.push(pip(dist[e.to][node.second],pii(e.to,node.second)));
                }
                if(node.second < ma){
                    if(dist[e.to][node.second+1] > dist[node.first][node.second] + e.cost/2){
                        dist[e.to][node.second+1] = dist[node.first][node.second] + e.cost/2;
                        q.push(pip(dist[e.to][node.second+1],pii(e.to,node.second+1)));
                    }
                }
            }
        }
        int ret = 1e9;
        rep(i,ma+1)ret = min(ret, dist[t][i]);
        return ret;
    }
};

int main(){
    int c,n,m,s,d;
    while(cin >> c >> n >> m >> s >> d, n){
        Dijkstra dij(n);
        rep(i,m){
            int a,b,f;
            cin >> a >> b >> f;
            dij.add(a-1,b-1,f);
        }
        cout << dij.calc(s-1,d-1,c) << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
int c,n,m,s,d;
const int INF = 2*1e9;
vector<pair<int,int>> G[100];
ll D[100][10];

struct P
{
	int time,v,chk;
	P(int time,int v,int chk)
	{
		this->time=time;
		this->v = v;
		this->chk = chk;
	}
};

bool operator<(P a,P b)
{
	return a.time>b.time;
}

void dijkstra(int chiket)
{
	for(int i = 0;i<100;i++)
	{
		for(int j = 0;j<10;j++)
		{
			D[i][j]=INF;
		}
	}
	D[s][chiket]=0;
	priority_queue<P> PQ;
	PQ.emplace(0,s,chiket);
	while(!PQ.empty())
	{
		//cout<<PQ.size()<<endl;
		auto now = PQ.top();
		PQ.pop();
		//cout<<now.time<<endl;
		if(D[now.v][now.chk]!=now.time)continue;
		for(auto next:G[now.v])
		{
			if(D[next.first][now.chk]>now.time+next.second)
			{
				D[next.first][now.chk]=now.time+next.second;
				PQ.emplace(D[next.first][now.chk],next.first,now.chk);
			}
			if(now.chk<1)continue;
			if(D[next.first][now.chk-1]>now.time+next.second/2)
			{
				D[next.first][now.chk-1] = now.time+next.second/2;
				PQ.emplace(D[next.first][now.chk-1],next.first,now.chk-1);
			}
		}
	}
	ll mn = INF;
	for(int i = 0;i<10;i++)
	{
		mn = min(mn,D[d][i]);
	}
	cout<<mn<<endl;
}

int main()
{
	while(1)
	{
		cin >> c >> n >> m >> s >> d;
		if(c==0)break;
		for(int i = 0;i<n;i++)
		{
			G[i].clear();
		}
		s--;
		d--;
		for(int i = 0;i<m;i++)
		{
			int a,b,f;
			cin >> a >> b >> f;
			a--;
			b--;
			G[a].emplace_back(b,f);
			G[b].emplace_back(a,f);
		}
		dijkstra(c);
	}
}