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

#define reep(i,n,m) for(int i=(n);i<(m);i++)
#define rep(i,n) reep(i,0,n)

using namespace std;

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

class Node{
public:
    int used;
    int p;
    int cost;
    Node(int u,int n,int c):used(u),p(n),cost(c){}

    bool operator<(const Node &a)const{
        return cost>a.cost;
    }
};

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

        vector<Edge> edge[101];
        rep(i,m){
            int a,b,f;
            cin >> a >> b >> f;
            edge[a].push_back(Edge(b,f));
            edge[b].push_back(Edge(a,f));
        }

        priority_queue<Node> Q;
        Q.push(Node(0,s,0));

        bool used[101][11] = {0};

        while(!Q.empty()){
            Node node = Q.top();Q.pop();
            if(used[node.p][node.used]){
                continue;
            }
            used[node.p][node.used] = true;

            int p = node.p;

            if(p==d){
                cout << node.cost << endl;
                break;
            }

            rep(i,edge[p].size()){
                Edge e = edge[p][i];
                int next = e.to;
                int cost = node.cost + e.cost;
                Q.push(Node(node.used,next,cost));
                if(node.used<c){
                    cost = node.cost + e.cost/2;
                    Q.push(Node(node.used+1,next,cost));
                }
            }
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
using namespace std;

#define MAX 10000000
#define n_MAX 101
#define c_MAX 11

int main() {

  while( true ) {

    long long int c, n, m, s, d;
    cin >> c >> n >> m >> s >> d;
    if ( n == 0 ) break;

    long long int l[n_MAX][n_MAX] = {0};

    for ( long long int i = 0; i < m; i++ ) {

      long long int a, b, f;
      cin >> a >> b >> f;
      l[a][b] = f;
      l[b][a] = f;

    }

    long long int t[c_MAX][n_MAX];
    for ( long long int j = 0; j <= c; j++ ) {
      for ( long long int i = 1; i <= n; i++ ) {
	t[j][i] = MAX;
      }
    }
    t[c][s] = 0;

    for ( long long int j = c; j >= 0; j-- ) {

      priority_queue< pair< int, int >, vector< pair< int, int > >, greater< pair< int, int > > > q;

      for ( long long int i = 1; i <= n; i++ ) {
	if ( t[j][i] < MAX ) {
	  q.push( make_pair( t[j][i], i ) );
	}
      }

      while( q.size() > 0 ) {

	pair< int, int > p;
	p = q.top();
	q.pop();
	long long int next = p.second;
	if ( t[j][next] < p.first ) continue;

	for ( long long int i = 1; i <= n; i++ ) {

	  if ( l[next][i] == 0 ) continue;
	  if ( t[j][i] > t[j][next] + l[next][i] ) {
	    t[j][i] = t[j][next] + l[next][i];
	    q.push( make_pair( t[j][i], i ) );
	  }
	  if ( j > 0 ) {
	    t[j - 1][i] = min( t[j - 1][i], t[j][next] + l[next][i] / 2 );
	  }

	}

      }

    }

    long long int ans = MAX;

    for ( long long int i = 0; i <= c; i++ ) {
      ans = min( ans, t[i][d] );
    }

    cout << ans << endl;

  }

  return 0;

}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define F first
#define S second


int c,n,m,s,d;
typedef struct{
  int to,cost;
}edge;

vector<edge> V[11*100];


int dijkstra(int from,int to){
  from=(c+1)*from+c;
  bool used[n*(c+1)];
  memset(used,0,sizeof(used));
  int len[n*(c+1)];
  rep(i,n*(c+1))len[i]=1<<23;
  len[from]=0;

  priority_queue<PI,vector<PI>,greater<PI> > Q;
  Q.push(mp(0,from));
  while(!Q.empty()){
    int cost=Q.top().F,tfrom=Q.top().S;Q.pop();
    if(used[tfrom])continue;
    used[tfrom]=true;
    rep(i,V[tfrom].size()){
      int tto=V[tfrom][i].to,tcost=V[tfrom][i].cost;
      if(used[tto])continue;
      len[tto]=min(len[tfrom]+tcost,len[tto]);
      Q.push(mp(len[tto],tto));
    }
  }
/*
  rep(i,n){
    rep(j,c+1)printf("%6d",len[i*(c+1)+j]);
    cout<<endl;
  }
*/
  int ans=len[to*(c+1)];
  rep(i,c+1)ans=min(ans,len[to*(c+1)+i]);
  return ans;
}

main(){
  while(cin>>c>>n>>m>>s>>d,c|n|m|s|d){
    --s,--d;
    rep(i,n*(c+1))V[i].clear();

    rep(j,m){
      int a,b,cost;
      cin>>a>>b>>cost;
      --a,--b;
      rep(i,c+1){
        V[a*(c+1)+i].pb((edge){b*(c+1)+i,cost});
        V[b*(c+1)+i].pb((edge){a*(c+1)+i,cost});
        if(i){
          V[a*(c+1)+i].pb((edge){b*(c+1)+i-1,cost/2});
          V[b*(c+1)+i].pb((edge){a*(c+1)+i-1,cost/2});
        }
      }
    }
/*
    rep(i,n*(c+1)){
      printf("%d ",i/(c+1)+1);
      rep(j,V[i].size()){
        printf("%d %6d ",V[i][j].to/(c+1)+1,V[i][j].cost);
      }
      cout<<endl;
    }
*/
    cout<<dijkstra(s,d)<<endl;
  }
}