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++: #pragma once

#include <vector>
#include <queue>
#include <algorithm>
#include <string.h>
template <size_t N, typename COST_T>
class Dijkstra
{
public:
	struct Path
	{
		int connectingIndex;
		COST_T cost;
	};

	struct Agent
	{
		int index;
		int prev_index;
		COST_T cost;

		bool operator<(const Agent& rhs) const
		{
			return cost > rhs.cost;
		}
	};

	Dijkstra()
	{
		init_paths();
	}

	void init_paths()
	{
		edges.assign(N, std::vector<Path>());
	}

	void add_path(int from, int to, COST_T cost)
	{
		edges[from].push_back(Path{ to, cost });
	}

	void add_path_undirected(int node1, int node2, COST_T cost)
	{
		edges[node1].push_back(Path{ node2, cost });
		edges[node2].push_back(Path{ node1, cost });
	}

	// returns cost
	// returns -1 if there is no reachable path
	COST_T find_shortest_path(int start, int goal)
	{
		// initialize
		que = std::priority_queue<Agent>();
		this->start = start;
		this->goal = goal;
		memset(defined, 0, sizeof defined);

		que.push(Agent{ start });
		while (!que.empty())
		{
			Agent agent = que.top(); que.pop();
				
			if (defined[agent.index])
			{
				continue;
			}
			defined[agent.index] = true;
			prev_node[agent.index] = agent.prev_index;

			if (agent.index == goal)
			{
				return agent.cost;
			}

			for (auto path : edges[agent.index])
			{
				if (!defined[path.connectingIndex])
				{
					que.push(Agent{ path.connectingIndex,
					                agent.index,
					                agent.cost + path.cost });
				}
			}
		}

		return -1;
	}

	std::vector<int> get_shortest_path() const
	{
		std::vector<int> path;
		int agent = goal;
		while (agent != start)
		{
			path.push_back(agent);
			agent = prev_node[agent];
		}
		path.push_back(start);
		std::reverse(path.begin(), path.end());
		return path;
	}

	std::vector<std::vector<Path>> edges;
	std::priority_queue<Agent> que;
	int start;
	int goal;
	int prev_node[N];
	bool defined[N];
};

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi; // 残りの割引券 現在の街
typedef pair<int, pi>P; // コスト pi
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

struct edge{ int to, cost; };

int C, V, E, S, D;
int d[128][16];
vector<vector<edge> >G(100);

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> >q;
  rep(i, V) rep(j, C+1) d[i][j] = INF;
  d[s][C] = 0;
  q.push(MP(0, MP(C, s)));

  while(!q.empty()){
    P p = q.top(); q.pop();
    int v = p.S.S;
    int c = p.S.F;

    rep(i, G[v].size()){
      edge e = G[v][i];
      if(d[e.to][c] > d[v][c] + e.cost){
	d[e.to][c] = d[v][c] + e.cost;
	q.push(MP(d[e.to][c], MP(c, e.to)));
      }

      if(c > 0){
	//	int cost = (e.cost/2)/100*100;
	if(d[e.to][c-1] > d[v][c] + e.cost/2){
	  d[e.to][c-1] = d[v][c] + e.cost/2;
	  q.push(MP(d[e.to][c-1], MP(c-1, e.to)));
	}
      }
    }
  }
}

int main(){
  while(scanf("%d%d%d%d%d", &C, &V, &E, &S, &D) && C+V+E+S+D){
    S--; D--;
    rep(i, V){
      G[i].clear();
    }
    rep(i, E){
      int a, b, c;
      scanf("%d%d%d", &a, &b, &c); a--; b--;
      edge e;
      e.to = a; e.cost = c;
      G[b].PB(e);
      e.to = b;
      G[a].PB(e);
    }

    dijkstra(S);

    printf("%d\n", d[D][0]);
  }

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <cassert>
#include <algorithm>
using namespace std;
typedef pair<int, int> edge;
struct state{
  int cost, coupon, station;
  state(int cost_, int coupon_, int station_):cost(cost_), coupon(coupon_), station(station_){}
  bool operator< (const state &s) const{
    if(cost == s.cost){
      return coupon > s.coupon;
    }
    return cost > s.cost;
  }
};
int djikstra(vector<vector<edge> > graph, int start, int goal, int coupon){
  priority_queue<state> pq;
  pq.push(state(0, coupon, start));
  bool visited[coupon][graph.size()];
  fill_n((bool*)visited, (coupon+1) * graph.size(), false);
  while(!pq.empty()){
    state cur = pq.top(); pq.pop();
    //cout << cur.station << ": " << cur.cost << ": " << cur.coupon << endl;
    if(visited[cur.coupon][cur.station]){
      continue;
    }
    if(cur.station == goal){
      return cur.cost;
    }
    visited[cur.coupon][cur.station] = true;
    for(int i = 0; i < graph[cur.station].size(); ++i){
      int to = graph[cur.station][i].first;
      int c = graph[cur.station][i].second;
      if(cur.coupon > 0){
        pq.push(state(cur.cost+c/2, cur.coupon-1, to));
      }
      pq.push(state(cur.cost+c, cur.coupon, to));
    }
  }
  //assert(false);
  return -1;
}
int main(){
  int c, n, m, s, d;
  while(true){
    cin >> c >> n >> m >> s >> d;
    if((c|n|m|s|d) == 0){
      break;
    }
    vector<vector<edge> > graph(n+1, vector<edge>());
    for(int i = 0; i < m; ++i){
      int a, b, f;
      cin >> a >> b >> f;
      graph[a].push_back(make_pair(b, f));
      graph[b].push_back(make_pair(a, f));
    }
    cout << djikstra(graph, s, d, c) << endl;
  }
  return 0;
}