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 <queue>
#include <algorithm>
#include <functional>
using namespace std;

int C, N, M, S, D; //??????????????°???????????°???????????°???????????°???????????°
int cost[101];
int INF = 999999999;

class Edge
{
public:
	int to, cost;
	Edge(int to, int cost) : to(to), cost(cost){}
};

class Vertax
{
public:
	int n;
	int cost;
	priority_queue<int, vector<int>, greater<int>> discount;
	Vertax(){}

	Vertax get(Edge e)
	{
		Vertax v = *this;
		if (discount.size() == C)
		{
			v.cost += e.cost / 2;
			v.discount.push(e.cost);
			v.cost += discount.top() / 2;
			v.discount.pop();
		}
		else
		{
			v.cost += e.cost / 2;
			v.discount.push(e.cost);
		}
		v.n = e.to;
		return v;
	}
};

bool operator > (Vertax v1, Vertax v2)
{
	return (v1.cost > v2.cost);
}
bool operator < (Vertax v1, Vertax v2)
{
	return (v1.cost < v2.cost);
}

priority_queue<Vertax, vector<Vertax>, greater<Vertax>> que;

int main()
{
	while (cin >> C >> N >> M >> S >> D, C + N + M + S + D)
	{
		fill(cost + 1, cost + N + 1, INF);
		vector<Edge> e[101];

		for (int i = 0; i < M; i++)
		{
			int from, to, cost;
			cin >> from >> to >> cost;
			e[from].push_back(Edge(to, cost));
			e[to].push_back(Edge(from, cost));
		}

		Vertax start;
		start.n = S;
		start.cost = 0;
		que.push(start);
		cost[S] = 0;

		while (!que.empty())
		{
			Vertax v = que.top();
			que.pop();

			for (int i = 0; i < e[v.n].size(); i++)
			{
				Edge edge = e[v.n][i];
				Vertax next = v.get(edge);
				if (cost[next.n] > next.cost)
				{
					cost[next.n] = next.cost;
					que.push(next);
				}
			}
		}

		cout << cost[D] << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#define INF 1000000000;
#define dis first
#define mati second.first
#define sta  second.second
using namespace std;
typedef pair <int ,pair <int,int> > P;
vector <P> mp[102];
int c,n,m,start,goal;

int bit_count(int a) {
  a = (a & 0x55555555)+((a & 0xAAAAAAAA) >> 1 );
  a = (a & 0x33333333)+((a & 0xCCCCCCCC) >> 2 );
  a = (a & 0x0F0F0F0F)+((a & 0xF0F0F0F0) >> 4 );
  a = (a & 0x00FF00FF)+((a & 0xFF00FF00) >> 8 );
  a = (a & 0x0000FFFF)+((a & 0xFFFF0000) >> 16);
  return a;
}
int dijkstra() {
  int flg[12][102] = {},dis[12][102];
  for(int j=0;j<=c;j++)
    for(int i=0;i<=n;i++) dis[j][i] = -INF;

  for(int j=1;j<=c;j++)flg[j][start] = 1;

  priority_queue <P> Q;
  P t;
  t.dis = 0, t.mati = start, t.sta = 0;
  Q.push(t);

  while(!Q.empty()) {
    t = Q.top(),Q.pop();
    if(flg[t.sta][t.mati] == 1) continue;
    flg[t.sta][t.mati] = 1;
    for(int i=0;i<mp[t.mati].size();i++){
      int ndis = mp[t.mati][i].dis;
      int nmati = mp[t.mati][i].mati;
      int nsta = t.sta+1;
      P tt;
      if(dis[t.sta][nmati] < t.dis-ndis && flg[t.sta][nmati] == 0) {
	tt.dis = t.dis-ndis,tt.mati = nmati,tt.sta = t.sta;
	dis[t.sta][nmati] = t.dis-ndis;
	Q.push(tt);
      }
      if(nsta<= c&&dis[nsta][nmati]<t.dis-ndis/2 && flg[nsta][nmati]==0){
	tt.dis = t.dis - ndis/2 , tt.mati = nmati, tt.sta = nsta;
	dis[nsta][nmati] = t.dis-ndis/2;
	Q.push(tt);
      }
    }
  }

  int ans = -INF;
  for(int j=0;j<=c;j++)ans = max(ans,dis[j][goal]);
   
  return -ans;
}


int main() {

  while(1) {
    cin >> c >> n >> m >> start >> goal;
    if(c==0&&n==0&&m==0&&start==0&&goal==0) break;

    for(int i=0;i<=n;i++) mp[i].clear();
    for(int i=0;i<m;i++) {
      int a,b,f;
      cin >> a >> b >> f;
      P t;
      t.dis = f,  t.mati = b , t.sta = 0;
      mp[a].push_back(t);
      t.mati = a;
      mp[b].push_back(t);
    }

    cout << dijkstra() << endl;
  }

  return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>

#define FOR(i,b,n) for(int i=b;i<n;i++)
#define RFOR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))

#define INF 100000000

using namespace std;

typedef pair<int,int> paii;

int c, n, m, s, d; 
int fare[1000][1000];
int vtx[1000][1000];
	
int solve()
{
	queue<paii> qu;
	CLR(vtx);
	
	FOR(i, 1, n+1)
	{
		FOR(j, 0, c+1)
		{
			if( i != s )
				vtx[i][j] = INF;
		}
	}
	
	qu.push(paii(s, c));
	
	while( !qu.empty() )
	{
		int nowv = qu.front().first;
		int nowt = qu.front().second;
		qu.pop();
		
		FOR(j, 1, n+1)
		{
			if(( j != nowv) && (fare[nowv][j] != 0))
			{
				if( vtx[j][nowt] > vtx[nowv][nowt] + fare[nowv][j] )
				{
					vtx[j][nowt] = vtx[nowv][nowt] + fare[nowv][j];
					qu.push(paii(j,nowt));
				}
				
				if( (nowt > 0) && (vtx[j][nowt-1] > vtx[nowv][nowt] + fare[nowv][j]/2) )
				{
					vtx[j][nowt-1] = vtx[nowv][nowt] + fare[nowv][j]/2;
					qu.push(paii(j,nowt-1));
				}
			}
		}
	}
	
	int res = INF;
	
	FOR(i, 0, c)
	{
		res = min(res, vtx[d][i]);
	}
	
	return res;
}

int main()
{
	while(cin >> c >> n >> m >> s >> d, (c||n||m||s||d))
	{
		CLR(fare);
		
		FOR(i, 0, m)
		{
			int a, b, f;
			cin >> a >> b >> f;
			
			fare[a][b] = f;
			fare[b][a] = f;
		}
		
		cout << solve() << endl;
	}
	
	return 0;
}