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<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<climits>

using namespace std;

typedef pair<int,pair<int,int> >P;

struct Edge{
  int to,cost;
  Edge(int _to, int _cost):to(_to), cost(_cost){};
};

int minCost[101][11];
vector<Edge> edge[101];
static const int INF = INT_MAX;

int c,n,m,s,d;

int dijkstra(void){
  priority_queue<P, vector<P>, greater<P> >que;
  que.push(make_pair(0,make_pair(s,c)));

  for(int i=0;i<=n;i++)
    for(int j=0;j<=n;j++)
      minCost[i][j]=INF;

  while(!que.empty()){
    P p = que.top();
    que.pop();

    if(p.second.first==d)return p.first;
    
    if(minCost[p.second.first][p.second.second] <= p.first)continue;
    minCost[p.second.first][p.second.second] = p.first;
    
    for(int i=0;i<edge[p.second.first].size();i++){
      Edge e = edge[p.second.first][i];
      que.push(make_pair(p.first+e.cost,make_pair(e.to,p.second.second)));
    }

    if(p.second.second==0)continue;
    
    for(int j=0;j<edge[p.second.first].size();j++){
      Edge e = edge[p.second.first][j];
      if(p.first+e.cost/2<minCost[e.to][p.second.second-1])
      que.push(make_pair(p.first+e.cost/2,make_pair(e.to,p.second.second-1)));
    }
  }
  return -1;
}

int main(void){
  int a,b,f;

  while(cin >> c >> n >> m >> s >> d,c|n|m|s|d){

    for(int i=0;i<=n;i++)edge[i].clear();

    for(int i=0;i<m;i++){
      cin >> a >> b >> f;
      edge[a].push_back(Edge(b,f));
      edge[b].push_back(Edge(a,f));
    }

    cout << dijkstra() << endl;
  }

  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;

#define TT template<typename T>
#define TTF template<typename T, typename F>
#define ET(T) typename T::value_type
TT inline T sq(T x){return x*x;}
TT inline T In(){T x;cin>>x;return x;}
TT inline void Out(T&x){cout<<x;}
TT inline void sort(T&v){sort(begin(v),end(v));}
TT inline void revs(T&v){reverse(begin(v),end(v));}
TT inline void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT inline int ubnd(T&v,ET(T)&x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT inline int lbnd(T&v,ET(T)&x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF inline void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF inline void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
#undef TT
#undef TTF
#undef ET

inline void fast_io(){ios::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}

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

struct Edge {
  int f, t, w, c;
  Edge(int f, int t, int w, int c=0) : f(f), t(t), w(w), c(c) {}
  bool operator<(const Edge& e) const {
    return w != e.w ? w > e.w : (f != e.f ? f < e.f : (t != e.t ? t < e.t : c < e.c));
  }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int dijkstra(const Graph& g, int s, int t, int c){
  int vis[128][16] = {};
  priority_queue<Edge> pq;
  for (pq.push(Edge(-2, s, 0)); !pq.empty(); pq.pop()){
    Edge e = pq.top();
    if (e.c > c) continue;
    if (vis[e.t][e.c]++) continue;
    if (e.t == t) return e.w;
    for (const auto& ee : g[e.t]){
      pq.push(Edge(e.t, ee.t, e.w + ee.w, e.c));
      pq.push(Edge(e.t, ee.t, e.w + ee.w / 2, e.c + 1));
    }
  }
  return -1;
}

int main()
{
  int c, n, m, s, d;
  while (cin >> c >> n >> m >> s >> d, c || n || m || s || d){
  Graph g(n + 1);
  for (int i = 0; i < m; i++){
    int a, b, f;
    cin >> a >> b >> f;
    g[a].push_back(Edge(a, b, f));
    g[b].push_back(Edge(b, a, f));
  }
  cout << dijkstra(g, s, d, c) << endl;
  }
  return (0);
}

// priority_queue queue deque front stringstream max_element min_element insert count make_tuple

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

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)

struct edge{
    int to, cost;
};

typedef pair<int, pair<int, int> > pii; // distance, edge, ticket

int INF = 10e8;
int c, n, m, s, d;

int dis[100][11];

int main(){
    while(1){
        cin >> c >> n >> m >> s >> d;

        if(n==0) break;

        vector<edge> g[100];
        REP(i, m){
            int a, b, f;
            cin >> a >> b >> f;
            edge ae;
            ae.to = b;
            ae.cost = f;
            g[a].push_back(ae);
            edge be;
            be.to = a;
            be.cost = f;
            g[b].push_back(be);
        }

        priority_queue<pii, vector<pii>, greater<pii> > que;
        REP(i, n+1){
            REP(j, c+1){
                dis[i][j] = INF;
            }
        }
        dis[s][c] = 0;
        pii init = make_pair(0, make_pair(s, c));
        que.push(init);

        while(!que.empty()){
            pii p = que.top();
            que.pop();

            int v = p.second.first;
            int t = p.second.second;
            if(dis[v][t]<p.first) continue;
            REP(i, g[v].size()){
                edge e = g[v][i];
                if(dis[e.to][t] > dis[v][t] + e.cost){
                    dis[e.to][t] = dis[v][t] + e.cost;
                    que.push(pii(make_pair(dis[e.to][t], make_pair(e.to, t))));
                }
                if(t>0){
                    if(dis[e.to][t-1] > dis[v][t] + e.cost / 2){
                        dis[e.to][t-1] = dis[v][t] + e.cost / 2;
                        que.push(pii(make_pair(dis[e.to][t-1], make_pair(e.to, t-1))));
                    }
                }
            }
        }
        /*
        REP(i, n+1){
            REP(j, c+1){
                cout << dis[i][j] << " ";
            }
            cout << endl;
        }
        */
        cout << dis[d][0] << endl;
    }
}