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 <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

struct edge { int to, cost; };
struct state {
  int cur, card, cost;
  bool operator<(const state& lhs) const {
    return cost > lhs.cost;
  }
};

typedef pair<int,int> P;

const int kInf = 1 << 28;
int C, N, M, S, D;
vector<edge> es[102];
int d[102][12];

int solve() {
  // init
  for (int i = 0; i < 102; ++i)
    for (int j = 0; j < 12; ++j)
      d[i][j] = kInf;
  // dijkstra
  priority_queue<state> Q;
  d[S][C] = 0;
  Q.push((state){S, C, 0});
  while (!Q.empty()) {
    state s = Q.top(); Q.pop();
    if (d[s.cur][s.card] < s.cost)
      continue;
    rep(i,es[s.cur].size()) {
      const edge& e = es[s.cur][i];
      // without ticket
      if (d[e.to][s.card] > s.cost + e.cost) {
        d[e.to][s.card] = s.cost + e.cost;
        Q.push((state){e.to, s.card, s.cost + e.cost});
      }
      // use ticket
      if (s.card > 0 &&
          d[e.to][s.card - 1] > s.cost + (e.cost / 2)) {
        d[e.to][s.card - 1] = s.cost + (e.cost / 2);
        Q.push((state){e.to, s.card - 1, s.cost + (e.cost / 2)});
      }
    }
  }
  return *min_element(d[D], d[D] + 12);
}

int main() {
  while (scanf("%d%d%d%d%d", &C, &N, &M, &S, &D), C) {
    --S; --D;
    rep(i,N) {
      es[i].clear();
    }
    rep(i,N) {
      int a, b, f;
      scanf("%d%d%d", &a, &b, &f);
      --a; --b;
      es[a].push_back((edge){b, f});
      es[b].push_back((edge){a, f});
    }
    printf("%d\n", solve());
  }
  return 0;
}

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

using namespace std;

const int INF = 10000000;

int city[101][101];

int solve( int s, int d, int c, int n ){
	int dist[11][101];
	int history[11][101];

	for( int i = 0;i < 11;i++ ){
		for( int j = 1;j < 101;j++ ){
			dist[i][j] = INF;
			history[i][j] = 0;
		}
	}


	dist[c][s] = 0;

	typedef pair<int,int> data;
	typedef pair<int,data> graph;
	priority_queue<graph,vector<graph>,greater<graph> > q;

	q.push( graph( 0, data( s, c ) ) );

	while( !q.empty() ){
		graph a = q.top();
		int u = a.second.first;
		int uc = a.second.second;
		q.pop();
		history[uc][u] = 1;

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

			if( history[uc][i] ) continue;
			if( dist[uc][i] > dist[uc][u] + city[u][i] ){
				dist[uc][i] = dist[uc][u] + city[u][i];
				q.push( graph( dist[uc][i], data( i, uc ) ) );
			}

			if( uc && dist[uc - 1][i] > dist[uc][u] + city[u][i] / 2 ){
				dist[uc - 1][i] = dist[uc][u] + city[u][i] / 2;
				q.push( graph( dist[uc - 1][i], data( i, uc - 1 ) ) );
			}
		}
	}
	int answer = INF;
	for( int i = 0;i < 11;i++ ) answer = min( dist[i][d], answer );
	return answer;

}

int main(int argc, char const* argv[])
{
	int c,n,m,s,d;

	while( cin >> c >> n >> m >> s >> d && c != 0 ){
		int a,b,f;
		for( int i = 1;i < 101;i++ ){
			for( int j = 1;j < 101;j++ ){
				city[i][j] = INF * 2;
			}
		}
		for( int i = 0;i < m;i++ ){
			cin >> a >> b >> f;
			city[a][b] = f;
			city[b][a] = f;
		}

		cout << solve( s, d, c, n ) << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#define INF (1e9)
#define N 102
#define C 11
using namespace std;

typedef struct state {
  int cost,pos,ticket;
  state (int a,int b,int c): cost(a),pos(b),ticket(c){} 
  bool operator < (const state &s)const{
    return cost > s.cost;
  }
} state;

void dijkstra(int);
int c,n,d[N][C],M[N][N];
int main(){
  int m,s,ind,a,b,f;
  while(1){
    cin >> c >> n >> m >> s >> ind;
    if(c==0&&n==0&&m==0&&s==0&&ind==0) break;
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
	M[i][j]=INF;
    for(int i=0;i<m;i++){
      cin >> a >> b >> f;
      M[a][b]=M[b][a]=f;
    }
    dijkstra(s);
    cout << d[ind][c] << endl;
  }
  return 0;
}
void dijkstra(int s){
  priority_queue< state > q;
  for(int i=1;i<=n;i++)
    for(int j=1;j<=c;j++)
      d[i][j]=INF;
  d[s][0]=0;
  q.push( (state){0,s,0} );
  while(!q.empty()){
    state r=q.top();
    q.pop();
    int cos=r.cost;
    int pos= r.pos;
    int ticket = r.ticket;

    if(d[pos][ticket]<cos) continue;

    for(int i=1;i<=n;i++){
      if( M[pos][i]==INF)continue;
      
      if(d[ i ][ ticket ] > d[pos][ticket] + M[pos][i]){

	d[i][ticket]=d[pos][ticket]+M[pos][i];
	q.push((state){d[i][ticket],i,ticket});
      }


      if(ticket == c)continue;
      
      if(d[i][ticket+1] > d[pos][ticket] + M[pos][i] / 2 ){
	d[i][ticket+1]=d[pos][ticket]+M[pos][i]/2;
	q.push((state){d[i][ticket+1],i,ticket+1});
      }
      
    }
  }
}