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 <cstdio>
#include <utility>
#include <queue>
#include <algorithm>
#define INF (1<<27)
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int> _P; //point chicket
typedef pair<int,_P> P; //cost _P
struct Edge {
	int to,cost;
	Edge(int _to,int _cost) {to=_to,cost=_cost;}
};
int dist[11][100];
vector<Edge> edges[100];
int main() {
	int c,n,m,s,d;
	while(scanf("%d %d %d %d %d",&c,&n,&m,&s,&d),c) {
		rep(i,n) edges[i].clear();
		rep(i,c+1) rep(j,n) dist[i][j]=INF;
		rep(i,m) {
			int a,b,f;
			scanf("%d %d %d",&a,&b,&f);
			edges[a-1].push_back(Edge(b-1,f));
			edges[b-1].push_back(Edge(a-1,f));
		}
		priority_queue<P,vector<P>,greater<P> > Q;
		Q.push(P(0,_P(s-1,c)));
		dist[c][s-1]=0;
		while(!Q.empty()) {
			P p=Q.top(); Q.pop();
			_P _p=p.second;
			if(dist[_p.second][_p.first]<p.first) continue;
			rep(i,edges[_p.first].size()) {
				if(dist[_p.second][edges[_p.first][i].to]>(p.first+edges[_p.first][i].cost)) {
					dist[_p.second][edges[_p.first][i].to]=(p.first+edges[_p.first][i].cost);
					Q.push(P(p.first+edges[_p.first][i].cost,_P(edges[_p.first][i].to,_p.second)));
				}
				if(_p.second>0&&(dist[_p.second-1][edges[_p.first][i].to]>(p.first+edges[_p.first][i].cost/2))) {
					dist[_p.second-1][edges[_p.first][i].to]=(p.first+edges[_p.first][i].cost/2);
					Q.push(P(p.first+edges[_p.first][i].cost/2,_P(edges[_p.first][i].to,_p.second-1)));
				}
			}
		}
		int sum=1<<30;
		rep(i,c+1)if(sum>dist[i][d-1])sum=dist[i][d-1];
		printf("%d\n",sum);
	}
}

C++: #include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
};

/** Problem0212 : Highway Express Bus **/
struct edge{
	int from, to, cost;
	edge(int f, int t, int c):from(f), to(t), cost(c){}
	edge(){}
};
vector<edge> G;

int main()
{
	int C, N, M, S, D;
	while (cin>>C>>N>>M>>S>>D, C) {
		S--, D--;
		G.clear();
		
		rep(i, M) {
			int a, b, f;
			cin>>a>>b>>f;
			a--, b--;
			G.push_back(edge(a, b, f));
			G.push_back(edge(b, a, f));
		}
		
		int d[100][11];
		fill(d[0], d[0]+100*11, INF);
		for (int i=0; i<=C; i++) d[S][i]=0;
		
		while (true) {
			bool update=false;
			
			for (int i=0; i<G.size(); i++) {
				edge e = G[i];
				for (int j=0; j<=C; j++) {
					if (d[e.to][j] > d[e.from][j] + e.cost) {
						d[e.to][j] = d[e.from][j] + e.cost;
						update = true;
					}
					
					
					if (j+1<=C) {
						if (d[e.to][j+1] > d[e.from][j]+e.cost/2) {
							d[e.to][j+1] = d[e.from][j]+e.cost/2;
							update = true;
						}
					}
				}
			}
			
			if (!update) break;
		}
		
		int ans = INF;
		for (int i=0; i<=C; i++) {
			ans = min(ans, d[D][i]);
		}
		cout << ans << endl;
	}
}

C++: /* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
/* }}} */

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

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T> void print(T x) {std::cout << x << '\n';}
template <typename T>
void print(std::vector<T>& v, std::string s = " ") {
  REP(i, v.size()) {
    if (i != 0) std::cout << s;
    std::cout << v[i];
  }
  std::cout << '\n';
}

/* }}} */

struct Edge {
  int to, cost;
};

vector<vector<Edge>> edge;

void dijkstra(int s, int c, vvi& dp)
{
  priority_queue<pii, vector<pii>, greater<pii>> pq;
  dp[s][c] = 0;
  pq.push(mp(0, s));

  while (!pq.empty()) {
    pii p = pq.top(); pq.pop();
    int cur = p.Se;
    if (dp[cur][c] < p.Fi) continue;
    for (auto e : edge[cur]) {
      int t = c == 0 ? dp[cur][c] + e.cost : min(dp[cur][c] + e.cost, dp[cur][c - 1] + e.cost / 2);
      if (dp[e.to][c] > t) {
        dp[e.to][c] = t;
        pq.push(mp(dp[e.to][c], e.to));
      }
    }
  }
}

signed main()
{
  int c, n, m, s, d;

  while (cin>>c>>n>>m>>s>>d, c||n||m||s||d) {
    s--; d--;
    edge = vector<vector<Edge>>(n);
    vvi dp(n, vi(c + 1, INF));
    REP(i, m) {
      int a = in() - 1, b = in() - 1, f = in();
      edge[a].pb(Edge{b, f});
      edge[b].pb(Edge{a, f});
    }
    REP(i, c + 1) {
      dijkstra(s, i, dp);
    }
    print(dp[d][c]);
  }

  return 0;
}