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++: /**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class HighwayExpressBus {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      while(true) {
        int c, n, m, s, d; cin >> c >> n >> m >> s >> d;
        s--; d--;
        if (c==0) return;

        vector<P> graph[(c+1)*n];
        int cost[(c+1)*n];
        rep(i, (c+1)*n) {
          cost[i] = INT_MAX/2;
        }

        while(m--) {
          int a, b, f; cin >> a >> b >> f;
          a--; b--;
          rep(i, c+1) {
            graph[a+i*n].emplace_back(b+i*n, f);
            graph[b+i*n].emplace_back(a+i*n, f);
          }
          rep(i, c) {
            graph[a+i*n].emplace_back(b+(i+1)*n, f/2);
            graph[b+i*n].emplace_back(a+(i+1)*n, f/2);
          }
        }

        priority_queue<P, vector<P>, greater<>> que;
        que.emplace(0, s);
        cost[s] = 0;
        while(!que.empty()) {
          auto p = que.top(); que.pop();
          if (p.first > cost[p.second]) continue;
          for(const auto& e: graph[p.second]) {
            if (cost[e.first] > p.first + e.second) {
              cost[e.first] = p.first + e.second;
              que.emplace(cost[e.first], e.first);
            }
          }
        }

        int ans = INT_MAX;
        rep(i, c+1) {
          chmin(ans, cost[d+n*i]);
        }
        cout << ans << endl;
      }

    }
};

signed main() {
  HighwayExpressBus solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

C++: #include<bits/stdc++.h>
#define MAX_V 101
using namespace std;

struct edge { 
  int to, cost;
  edge(){}
  edge(int to,int cost):to(to),cost(cost){};
};
typedef pair<int ,int> P;
const int INF = 1 << 30;
int V; //ノードの数
vector<edge> Graph[MAX_V];
int min_cost[11][MAX_V];

int c,m,s,d;
void Dijkstra(int s,int chip){ // s:スタートからの最小コストをmin_costに設定
  priority_queue<P,vector< P >, greater<P> > que;
  fill(min_cost[chip],min_cost[chip] + V,INF);
  min_cost[chip][s] = 0;
  que.push(P(0,s));
  
  while(!que.empty()){
    P p = que.top();que.pop();
    int now = p.second;
    int cost = p.first;
    if(min_cost[chip][now] < cost) continue;
    
    for(int i = 0; i < Graph[now].size(); i++){
      edge e = Graph[now][i];
      int a;
      if(chip == 0){
	a = min_cost[chip][now] + e.cost;
      }else{
	a = min(min_cost[chip][now] + e.cost, min_cost[chip-1][now] + e.cost / 2);
	if(min_cost[chip][e.to] > a){
	  min_cost[chip][e.to] = a;
	  que.push(P(min_cost[chip][e.to], e.to));
	}
      }
    }
  }
}

int main(){
  
  while(cin >> c >> V >> m >> s >> d && (c||V||m||s||d)){
    s--;
    d--;
    
    for(int i=0;i<m;i++){
      int a,b,f;
      cin>>a>>b>>f;
      a--;b--;
      Graph[a].push_back(edge(b,f));
      Graph[b].push_back(edge(a,f));
    }
    
    for(int i=0;i<=c;i++){
      Dijkstra(s,i);
    }

    cout<<min_cost[c][d]<<endl;
    
    for(int i=0;i<MAX_V;i++) Graph[i].clear();
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
struct edge
{
	int to,cost;
	edge(int to,int cost):to(to),cost(cost){}
};
int c,n,m,s,d;
int id(int index,int rem)
{
	return ((c+1)*index+rem);
}
vector<edge> g[2000];
int dist[2000];
void dijkstra()
{
	for(int i=0;i<2000;i++)dist[i]=INF;
	dist[id(s,c)]=0;
	priority_queue<P,vector<P>,greater<P> > q;
	q.push(P(0,id(s,c)));
	while(!q.empty())
	{
		P a=q.top();
		q.pop();
		int v=a.sec;
		if(dist[v]<a.fi)continue;
		for(int i=0;i<g[v].size();i++)
		{
			edge e=g[v][i];
			if(dist[e.to]>dist[v]+e.cost)
			{
				dist[e.to]=dist[v]+e.cost;
				q.push(P(dist[e.to],e.to));
			}
		}
	}
	return;
}
int main()
{
	while(1)
	{
		scanf("%d %d %d %d %d",&c,&n,&m,&s,&d);
		if(c==0&&n==0&&m==0&&s==0&&d==0)break;
		s--;d--;
		for(int i=0;i<2000;i++)g[i].clear();
		for(int i=0;i<m;i++)
		{
			int A,B,C;
			scanf("%d %d %d",&A,&B,&C);
			A--;B--;
			for(int j=0;j<=c;j++)
			{
				g[id(A,j)].pb(edge(id(B,j),C));
				g[id(B,j)].pb(edge(id(A,j),C));
			}
			for(int j=1;j<=c;j++)
			{
				g[id(A,j)].pb(edge(id(B,j-1),C/2));
				g[id(B,j)].pb(edge(id(A,j-1),C/2));
			}
		}
		dijkstra();
		int ans=INF;
		for(int i=0;i<=c;i++)ans=min(ans,dist[id(d,i)]);
		printf("%d\n",ans);
	}
	return 0;
}