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]int)
		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}] = now.Amount
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				if memoAmount, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok || (ok && memoAmount > next.Amount) {
					memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}] = next.Amount
					heap.Push(&pq, next)
				}
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					if memoAmount, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok || (ok && memoAmount > next.Amount) {
						memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}] = next.Amount
						heap.Push(&pq, next)
					}
				}
			}
		}
		runtime.GC()
	}
}

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

using namespace std;
#define INF 99999999
typedef pair<int, int> P;
typedef pair<P, int> PP;
struct Edge
{
	int to;
	int cost;
};

void solve()
{
	int c, n, m, s, d;
	while(cin >> c >> n >> m >> s >> d, c || n || m || m || s)
	{
		vector<Edge> V[101];
		for(int i = 0; i < m; ++i)
		{
			int from, to, cost;
			cin >> from >> to >> cost;
			--from; --to;
			Edge e1 = {to, cost};
			Edge e2 = {from, cost};
			V[from].push_back(e1);
			V[to].push_back(e2);
		}
		vector< vector<int> > dist(n, vector<int>(c + 1));
		for(int i = 0; i < dist.size(); ++i)
		{
			for(int j = 0; j < dist[i].size(); ++j)
			{
				dist[i][j] = INF;
			}
		}
		priority_queue<PP, vector<PP>, greater<PP> > pq;
		--s;
		dist[s][0] = 0;
		pq.push(PP(P(0, s), 0));
		while(!pq.empty())
		{
			PP pp = pq.top();
			pq.pop();
			int v = pp.first.second;
			int ticket = pp.second;
			if(dist[v][ticket] < pp.first.first)
			{
				continue;
			}
			for(int i = 0; i < V[v].size(); ++i)
			{
				Edge e = V[v][i];
				if(dist[e.to][ticket] > pp.first.first + e.cost)
				{
					dist[e.to][ticket] = pp.first.first + e.cost;
					pq.push(PP(P(dist[e.to][ticket], e.to), ticket));
				}
				if(ticket < c && dist[e.to][ticket + 1] > pp.first.first + e.cost / 2)
				{
					dist[e.to][ticket + 1] = pp.first.first + e.cost / 2;
					pq.push(PP(P(dist[e.to][ticket + 1], e.to), ticket + 1));
				}
			}
		}
		int min_cost = INF;
		for(int i = 0; i <= c; ++i)
		{
			if(min_cost > dist[d - 1][i])
			{
				min_cost = dist[d - 1][i];
			}
		}
		cout << min_cost << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int INF = 1e9;

int C, N, M, S, T;

class Cl{
  public:
    int n, c, cost;
    Cl(){}
    Cl(int nn, int cc, int co) { n = nn; c = cc; cost = co; }
    bool operator < (const Cl &tmp) const { return cost > tmp.cost; }
};

int solve(vector< vector<P> > &v){
  priority_queue<Cl> open;
  open.push(Cl(S, C, 0));
  vector< vector<int> > closed(N, vector<int>(C + 1, INF));
  closed[S][C] = 0;
  while(!open.empty()){
    Cl cl = open.top(); open.pop();
    if(closed[cl.n][cl.c] < cl.cost) continue;
    REP(i, v[cl.n].size()){
      P nx = v[cl.n][i];
      if(closed[nx.first][cl.c] > cl.cost + nx.second){
        closed[nx.first][cl.c] = cl.cost + nx.second;
        open.push(Cl(nx.first, cl.c, cl.cost + nx.second));
      }
      if(cl.c > 0 && closed[nx.first][cl.c - 1] > cl.cost + nx.second / 2){
        closed[nx.first][cl.c - 1] = cl.cost + nx.second / 2;
        open.push(Cl(nx.first, cl.c - 1, cl.cost + nx.second / 2));
      }
    }
  }
  int res = INF;
  REP(i, C) res = min(res, closed[T][i]);
  return res;
}

int main() {
  while(cin >>C >>N >>M >>S >>T && C && N && M && S && T){
    --T; --S;
    vector< vector<P> > v(N);
    REP(i, M){
      int a, b, f; cin >>a >>b >>f;
      --a; --b;
      v[a].push_back(P(b, f));
      v[b].push_back(P(a, f));
    }
    cout <<solve(v) <<endl;
  }
  return 0;
}

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

const double PI = acos(-1);
const double EPS = 1e-15;
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
const ll MOD1 = 998244353;
typedef pair<int,int> P;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define mp make_pair

int main(){
  int c,n,m,s,d;
  while (cin >> c >> n >> m >> s >> d,c,n,m,s,d) {
    ll dp[110][11];
    REP(i,110) REP(j,11) dp[i][j] = INF;
    s--;
    d--;
    vector<pair<int,ll>> G[110];
    REP(i,m) {
      int a,b;
      ll f;
      cin >> a >> b >> f;
      a--;
      b--;
      G[a].pb({b,f});
      G[b].pb({a,f});
    }
    priority_queue<pair<ll,pair<int,int>>,vector<pair<ll,pair<int,int>>>,greater<pair<ll,pair<int,int>>>> pq;
    dp[s][0] = 0;
    pq.push({0,{s,0}});
    while (!pq.empty()) {
      pair<ll,pair<int,int>> tp = pq.top();
      //cout << tp.fi << " " << tp.se.fi << " " << tp.se.se << endl;
      pq.pop();
      int point = tp.se.fi;
      int ticket = tp.se.se;
      if (tp.fi > dp[point][ticket]) continue;
      //cout << "test" << endl;
      REP(i,sz(G[point])) {
        int next = G[point][i].fi;
        ll cost = G[point][i].se;
        if (dp[point][ticket] + cost < dp[next][ticket]) {
          dp[next][ticket] = dp[point][ticket] + cost;
          pq.push({dp[next][ticket],{next,ticket}});
        }
        if (ticket < c && dp[point][ticket] + cost/2 < dp[next][ticket+1]) {
          dp[next][ticket+1] = dp[point][ticket] + cost/2;
          pq.push({dp[next][ticket+1],{next,ticket+1}});
        }
      }
    }
    ll ans = INF;
    REP(i,c+1) {
      ans = min(ans,dp[d][i]);
    }
    cout << ans << endl;
  }
  return 0;
}