Go: package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

const INF = 0x7FFFFFFF

var pass [][]int

func main() {
	for scanner.Scan() {
		pass = make([][]int, 200)
		for i := range pass {
			pass[i] = make([]int, 200)
		}
		buf := strings.Split(scanner.Text(), " ")
		c, _ := strconv.Atoi(buf[0])
		n, _ := strconv.Atoi(buf[1])
		m, _ := strconv.Atoi(buf[2])
		s, _ := strconv.Atoi(buf[3])
		d, _ := strconv.Atoi(buf[4])
		if c == 0 && n == 0 && m == 0 && s == 0 && d == 0 {
			break
		}
		s--
		d--
		for i := 0; i < 200; i++ {
			for j := 0; j < 200; j++ {
				pass[i][j] = INF
			}
		}
		for i := 0; i < 200; i++ {
			pass[i][i] = 0
		}
		for i := 0; i < m; i++ {
			scanner.Scan()
			buf_ := strings.Split(scanner.Text(), " ")
			a, _ := strconv.Atoi(buf_[0])
			b, _ := strconv.Atoi(buf_[1])
			f, _ := strconv.Atoi(buf_[2])
			a--
			b--
			pass[a][b] = f
			pass[b][a] = f
		}
		fmt.Println(dijkstra(s, d, c, n))
	}
}

func dijkstra(s, g, c, n int) float64 {
	d := make([][]float64, 200)
	used := make([][]bool, 200)
	for i := 0; i < 200; i++ {
		d[i] = make([]float64, 20)
		used[i] = make([]bool, 20)
	}
	for i := range d {
		for j := range d[i] {
			d[i][j] = INF
		}
	}
	d[s][c] = 0
	for {
		v := -1
		w := -1
		for u := 0; u < n; u++ {
			for i := 0; i < c+1; i++ {
				if !used[u][i] && (v == -1 || d[u][i] < d[v][w]) {
					v = u
					w = i
				}
			}
		}
		if v == -1 {
			break
		}
		used[v][w] = true
		for u := 0; u < n; u++ {
			d[u][w] = math.Min(d[u][w], d[v][w]+float64(pass[v][u]))
			if w-1 >= 0 && pass[v][u] != INF {
				d[u][w-1] = math.Min(d[u][w-1], d[v][w]+(float64(pass[v][u]/2.0)))
			}
		}
	}
	ret := float64(INF)
	for i := 0; i < c+1; i++ {
		ret = math.Min(ret, d[g][i])
	}
	return ret
}

C++: #include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <unordered_set>
//#include <unordered_map>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	int c,n,m,d,s;
	while(cin>>c>>n>>m>>s>>d,c||n||m||s||d){
		vvint dp;
		initvv(dp,n,c+1,-1);
		VV(pii) vv(n);
		rep(i,m){
			int a,b,f;
			cin>>a>>b>>f;
			vv[a-1].PB(mkp(b-1,f));
			vv[b-1].PB(mkp(a-1,f));
		}
		priority_queue<pair<int,pii>> pq;
		pq.push(mkp(0,pii(s-1,c)));
		while(!pq.empty()){
			pair<int,pii> top=pq.top();
			pq.pop();
			if(dp[top.S.F][top.S.S]!=-1){
				continue;
			}	
			dp[top.S.F][top.S.S]=-top.F;
			rep(i,vv[top.S.F].size()){
				if(dp[vv[top.S.F][i].F][top.S.S]==-1){
					pq.push(mkp(top.F-vv[top.S.F][i].S,pii(vv[top.S.F][i].F,top.S.S)));
				}
				if(top.S.S>=1&&dp[vv[top.S.F][i].F][top.S.S-1]==-1){
					pq.push(mkp(top.F-vv[top.S.F][i].S/2,pii(vv[top.S.F][i].F,top.S.S-1)));
				}
			}
		}
		int ans=INF;
		rep(i,dp[d-1].size()){
			ans=min(ans,dp[d-1][i]);
		}
		cout<<ans<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

C++: #include "bits/stdc++.h"
using namespace std;
const int MOD = (int)1e9 + 7, INF = (1 << 27); const ll INFLL = (1LL << 55);
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
template<typename T> void dbg(T x) { cout << x << "\n"; }
template<typename T, typename U> static void chmin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void chmax(T &x, U y) { if (x < y) x = y; }


int n, m;

// O(n^2)
using Dist = int;
const int VMAX = 110;
Dist cost[VMAX][VMAX];
Dist d[12][VMAX];
void dijkstra(int s, int a) {
    d[a][s] = 0;
    vector<int> used(n, 0);
    while (1) {
        int v = -1;
        for (int to = 0; to < n; to++) {
            if (used[to]) continue;
            if (v == -1 || d[a][to] < d[a][v]) v = to;
        }
        if (v == -1) break;
        used[v] = 1;
        for (int to = 0; to < n; to++) {
            Dist nd = d[a][v] + cost[v][to];
            if (a > 0) chmin(nd, d[a - 1][v] + cost[v][to] / 2);
            if (nd < d[a][to]) d[a][to] = nd;
        }
    }
}

void init() {
    fill_n(*d, 12 * VMAX, INF);
    fill_n(*cost, VMAX * VMAX, INF);
}

int main() {
    int c, s, t;
    while (cin >> c >> n >> m >> s >> t, c) {
        init();
        s--; t--;
        rep(i, m) {
            int a, b, f; cin >> a >> b >> f;
            a--; b--;
            cost[a][b] = cost[b][a] = f;
        }
        rep(a, c + 1) dijkstra(s, a);
        cout << d[c][t] << "\n";
    }

    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;// F -> to, S -> cost
typedef pair<P,int> PP;// F->P(to,cost), S->discount
int c,n,m,s,d;
vector<P> vec[1000]; // F -> pos , S -> cost
int MD[1000][13];
const int INF = 1<<27;

//C++だとなぜかRuntimeErrorになったので仕様変更
//vecにはコストいらないからvector<PP> vec -> vector<P> vec へ


void dijkstra(){
  priority_queue<PP,vector<PP>,greater<PP> > que;
  rep(i,n+1)rep(j,13)MD[i][j] = INF;
  //syokika
  MD[s][c] = 0;
  que.push(PP(P(0,s),c));//dis,start,discount

  while(!que.empty() ){
    PP p = que.top();que.pop(); //priority_queのPPと
    int v = p.F.S;
    
    for(int i=0;i<vec[v].size();i++){
      P po = vec[v][i]; //vectorのPPは意味が違うので注意！！！
      //if(MD[v][po.S] < po.F.S)continue;
      if(MD[po.F][p.S] > p.F.F + po.S){
	MD[po.F][p.S] = p.F.F+po.S;
	que.push(PP(P(MD[po.F][p.S],po.F),p.S));
      }
      if(p.S > 0 && MD[po.F][p.S-1] > p.F.F + po.S/2 ){
	MD[po.F][p.S-1] = p.F.F+po.S/2;
	que.push(PP(P(MD[po.F][p.S-1],po.F),p.S-1));
   
      }
    }
  }
}


int main(){
  int x,y,co;
  while(true){
    cin >> c >> n >> m >> s >> d;
    if(c+n+m+s+d == 0)break;
    rep(i,1000)vec[i].clear();
    rep(i,m){
      cin >> x >> y >> co;
      vec[x].push_back(P(y,co));
      vec[y].push_back(P(x,co));
    }
    dijkstra();
    int ans = INF;
    for(int i=0;i<=c;i++){
      ans = min(ans,MD[d][i]);
    }
    cout << ans << endl;
  }
  return 0;
}

//Version.1