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 <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

typedef int Weight;
struct Edge {
  int cnt;
  int src;
  int dest;
  Weight weight;
  Edge(int cnt, int src, int dest, Weight weight) : cnt(cnt), src(src), dest(dest), weight(weight) {;}
  bool operator<(const Edge &rhs) const {
    return weight > rhs.weight;
  }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int c, n, m, s, d;
bool visit[20][110];

int main() {
  while (scanf("%d %d %d %d %d", &c, &n, &m, &s, &d), c|n|m|s|d) {
    MEMSET(visit, false);
    s--; d--;
    Graph g(n);
    REP(i, m) {
      int f, t, cost;
      scanf("%d %d %d", &f, &t, &cost);
      f--; t--;
      g[f].push_back(Edge(0xdeadbeaf, 0xdeadbeaf, t, cost));
      g[t].push_back(Edge(0xdeadbeaf, 0xdeadbeaf, f, cost));
    }
    priority_queue<Edge> que;
    que.push(Edge(c, 0xdeadbeaf, s, 0));
    while (!que.empty()) {
      Edge e = que.top();
      que.pop();
      if (visit[e.cnt][e.dest]) { continue; }
      visit[e.cnt][e.dest] = true;
      if (e.dest == d) {
        printf("%d\n", e.weight);
        break;
      }
      FORIT(it, g[e.dest]) {
        if (e.cnt != 0) {
          int ncost = e.weight + it->weight / 2;
          que.push(Edge(e.cnt - 1, 0xdeadbeaf, it->dest, ncost));
        }
        int ncost = e.weight + it->weight;
        que.push(Edge(e.cnt, 0xdeadbeaf, it->dest, ncost));
      }
    }
  }
}

C++: #include <iostream>
#include <queue>
#include <algorithm>
#include <cstring>

#define MAX 1000000000
#define Debug(X) debug( __LINE__, X )
template<class T>
void debug( int line, T dbg ){
	std::cout << line << ": " << dbg << std::endl;
}

class State{
public:
	int p, s, c;
	State():p(0), s(0), c(0){}
	State(int P, int S, int C):p(P), s(S), c(C){}
	bool operator < (const State &s) const{
		return c > s.c;
	}
};

int c, n, m, s, d;
int route[101][101];
std::priority_queue<State> que;
bool used[101][11];


int main(){
	while( std::cin >> c >> n >> m >> s >> d, c * n * m * s * d ){
		for( int i = 0; i < 101 * 101; ++i )
			route[i / 101][i % 101] = MAX;
		
		memset( used, 0, sizeof( used ) );
		que = std::priority_queue<State>();

		int tmp[3];
		while( m-- ){
			int cnt = 3;
			while( cnt-- ) std::cin >> tmp[2 - cnt];

			route[tmp[0]][tmp[1]] = tmp[2];
			route[tmp[1]][tmp[0]] = tmp[2];
		}

		que.push(State( c, s, 0 ));

		while( true ){
			State data = que.top(); que.pop();

			if( used[data.s][data.p] )continue;
			used[data.s][data.p] = 1;

			if( data.s == d ){
				std::cout << data.c << std::endl;
				break;
			}

			for( int i = 1; i <= n; ++i ){
				if( i == data.s || route[data.s][i] == MAX )continue;

				if( data.p > 0 )
					que.push( State( data.p - 1, i, data.c + route[data.s][i] / 2 ) );

				que.push( State( data.p, i, data.c + route[data.s][i] ) );				
			}

		}

	}
}

C++: #include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;
#define INF 1e+9
typedef pair<int,int> P;
struct edge{
    int to,cost;
};
int c,n,m,s,end;
vector<edge> G[101];
int d[11][101];

void dijkstra(int s,int a){
    priority_queue<P, vector<P>, greater<P> >Q;
    for(int i=0;i<n;i++)d[a][i] = INF;
    d[a][s] = 0;
    Q.push(P(0,s));
    
    while(!Q.empty()){
        P p=Q.top();
        Q.pop();
        int v = p.second;
        
        if(d[a][v] < p.first)continue;
        for(int i=0;i<G[v].size();i++){
            edge e = G[v][i];
            int dm;
            if(a==0)dm=d[a][v]+e.cost;
            else dm=min(d[a][v]+e.cost,d[a-1][v]+e.cost/2);
            if(d[a][e.to] > dm){
                d[a][e.to] = dm;
                Q.push(P(d[a][e.to],e.to));
            }
        }
    }
}

int main() {
    while(1){
     cin>>c>>n>>m>>s>>end;
     s--;
     end--;
     if(!c)break;
     
     for(int i=0;i<m;i++){
         int a,b,f;
         cin>>a>>b>>f;
         a--;
         b--;
         G[a].push_back((edge){b,f});
         G[b].push_back((edge){a,f});
     }
     int ans = INF;
     for(int i=0;i<=c;i++){
         dijkstra(s,i);
	 }
        
     cout<<d[c][end]<<endl;
     
     for(int i=0;i<100;i++)G[i].clear();
	}
	return 0;
}