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

#define MAX 110
#define INF (1<<29)
typedef pair<int, int> P;
typedef pair<int, P> P2;

struct edge{
  int to, cost;
};

vector<edge> G[MAX];
int V[MAX][11];
int ticket, n, m, s, d;

int dijkstra(){
  for(int i = 0 ; i < n ; i++)
    for(int j = 0 ; j < 11 ; j++) V[i][j] = INF;
  
  priority_queue<P2, vector<P2>, greater<P2> > que;
  
  que.push(P2(0, P(s, 0)));
  V[s][0] = 0;
  
  while(!que.empty()){
    P2 q = que.top(); que.pop();
    int v = q.second.first;
    int cnt = q.second.second;
    if(V[v][cnt] < q.first) continue;
    
    for(int i = 0 ; i < G[v].size() ; i++){
      edge e = G[v][i];
      if(V[e.to][cnt] > V[v][cnt] + e.cost){
	V[e.to][cnt] = V[v][cnt] + e.cost;
	que.push(P2(V[e.to][cnt], P(e.to, cnt)));
      }
      if(cnt >= ticket) continue;
      
      if(V[e.to][cnt+1] > V[v][cnt] + e.cost/2){
	V[e.to][cnt+1] = V[v][cnt] + e.cost/2;
	que.push(P2(V[e.to][cnt+1], P(e.to, cnt+1)));
      }
    }
  }
  int ret = INF;
  for(int i = 0 ; i <= ticket ; i++){
    ret = min(ret, V[d][i]);
  }
  return ret;
}

int main(){
  while(cin >> ticket >> n >> m >> s >> d){
    if(!ticket && !n && !m && !s && !d) break;
    s--, d--;    
    for(int i = 0 ; i < n ; i++) G[i].clear();
    int from, to, cost;
    for(int i = 0 ; i < m ; i++){
      cin >> from >> to >> cost;
      from--, to--;
      edge e;
      //無向グラフ
      e.to = to, e.cost = cost;
      G[from].push_back(e);
      e.to = from; 
      G[to].push_back(e);
    }
    cout << dijkstra() << endl;
  }
  return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

struct Edge {
	int v, f, c;
	bool operator > (const Edge& e) const { return f > e.f; }
};

int c, n, m, s, d;
vector< vector< Edge > > edges;

int cost[111][11];

int djk() {
	for_(i,0,111) for_(j,0,11) cost[i][j] = (int)1e9;
	
	priority_queue< Edge, vector< Edge >, greater< Edge > > que;
	que.push(Edge{s, 0, c});
	cost[s][c] = 0;
	
	while (!que.empty()) {
		Edge e = que.top(); que.pop();
		
		for (Edge& ei : edges[e.v]) {
			if (cost[ei.v][e.c] > e.f + ei.f) {
				cost[ei.v][e.c] = e.f + ei.f;
				que.push(Edge{ei.v, e.f + ei.f, e.c});
			}
			
			if (e.c > 0 && cost[ei.v][e.c - 1] > e.f + ei.f / 2) {
				cost[ei.v][e.c - 1] = e.f + ei.f / 2;
				que.push(Edge{ei.v, e.f + ei.f / 2, e.c - 1});
			}
		}
	}
	
	int ans = (int)1e9;
	for_(i,0,11) ans = min(ans, cost[d][i]);
	
	return ans;
}

int main() {
	while (cin >> c >> n >> m >> s >> d, n) {
		--s; --d;
		
		edges.assign(n, vector< Edge >());
		
		for_(i,0,m) {
			int a, b, f;
			cin >> a >> b >> f;
			--a; --b;
			edges[a].push_back(Edge{b, f, 0});
			edges[b].push_back(Edge{a, f, 0});
		}
		
		cout << djk() << endl;
	}
}

C++: #include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)

#define MP       make_pair
#define PB       push_back
#define ALL(x)   (x).begin(),(x).end()

const int INF = 1<<29;
const double EPS = 1e-9;
double zero(double d){
  return d < EPS ? 0.0 : d;
}

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


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(7);

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

    int dis[11][101];
    bool used[11][101];
    int cost[101][101];

    REP(i,11){
      fill( dis[i], dis[i]+101, INF );
      fill( used[i], used[i]+101, false );
    }
    dis[0][s] = 0;

    REP(i,101){
      fill( cost[i], cost[i]+101, INF );
      cost[i][i] = 0;
    }

    REP(_t,m){
      int a,b,f;
      cin >> a >> b >> f;
      cost[a][b] = cost[b][a] = f;
    }


    while(true){

      // pick minimum distance in unused
      int mini=-1, minj=0;
      REP(i,c+1){
	REP(j,n+1){
	  if( ! used[i][j] ){
	    if( mini==-1 || dis[mini][minj] > dis[i][j] ){
	      mini = i;
	      minj = j;
	    }
	  }
	}
      }

      if( mini == -1)	break;
      used[mini][minj] = true;

      REP(i,m+1){
	dis[mini][i] = min( dis[mini][i], dis[mini][minj] + cost[minj][i] );
	if( mini + 1 <= c )
	  dis[mini+1][i] = min( dis[mini+1][i], dis[mini][minj] + cost[minj][i]/2 );	  
      }
    }

    int res=INF;
    REP(i,c+1)
      res = min( res, dis[i][d] );

    cout << res << endl;
  }

  return 0;
}