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

#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 distance;
    int num;
    int ticket;
    Node(){}
    Node(int distance, int num,int ticket):distance(distance),num(num),ticket(ticket){}
    bool operator<(const Node &b)const{
        return distance > b.distance;
    }
};

vector<Edge> edge[101];
bool flg[101][11];

void init(){
    rep(i,101){
        edge[i].clear();
        rep(k,11){
            flg[i][k] = 0;
        }
    }
}

int main(){
    int c,n,m,s,d;
    while(cin >> c >> n >> m >> s >> d,!m==0){
        init();
        rep(i,m){
            int a,b,c;
            cin >> a >> b >> c;
            edge[a].push_back(Edge(b,c));
            edge[b].push_back(Edge(a,c));
        }
        priority_queue<Node> Q;
        Q.push(Node(0,s,0));
        int ans = 1000000;
        while(!Q.empty()){
            Node node = Q.top();Q.pop();
            if(flg[node.num][node.ticket]){
                continue;
            }
            flg[node.num][node.ticket] = true;
            //printf("num->%d cost->%d ticket->%d\n",node.num,node.distance,node.ticket);
            if(node.num == d){
                ans = min(ans,node.distance);
            }

            rep(i,edge[node.num].size()){
                Edge e = edge[node.num][i];
                int cost = node.distance + e.cost;
                Q.push(Node(cost,e.to,node.ticket));
                if(node.ticket < c){
                    int cost = node.distance + e.cost/2;
                    Q.push(Node(cost,e.to,node.ticket+1));
                }
            }
        }
        cout << ans << endl;
    }
}

C++: #include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
};

/** Problem0212 : Highway Express Bus **/
struct edge{
	int from, to, cost;
	edge(int f, int t, int c):from(f), to(t), cost(c){}
	edge(){}
};
vector<edge> G;

int main()
{
	int C, N, M, S, D;
	while (cin>>C>>N>>M>>S>>D, C) {
		S--, D--;
		G.clear();
		
		rep(i, M) {
			int a, b, f;
			cin>>a>>b>>f;
			a--, b--;
			G.push_back(edge(a, b, f));
			G.push_back(edge(b, a, f));
		}
		
		int d[100][11];
		fill(d[0], d[0]+1000, INF);
		for (int i=0; i<C+1; i++) d[S][i]=0;
		
		while (true) {
			bool update=false;
			
			for (int i=0; i<G.size(); i++) {
				edge e = G[i];
				for (int j=0; j<=C; j++) {
					if (d[e.to][j] > d[e.from][j] + e.cost) {
						d[e.to][j] = d[e.from][j] + e.cost;
						update = true;
					}
					
					
					if (j<=C) {
						if (d[e.to][j+1] > d[e.from][j]+e.cost/2) {
							d[e.to][j+1] = d[e.from][j]+e.cost/2;
							update = true;
						}
					}
				}
			}
			
			if (!update) break;
		}
		
		int ans = INF;
		for (int i=0; i<C+1; i++) {
			ans = min(ans, d[D][i]);
		}
		cout << ans << endl;
	}
}

C++: #include <cstdio>
#include <iostream>
#include <string>
#include <queue>
#define INF (1<<21)
using namespace std;

class State{
public:
  int n,cost,c,f;
  State(int n = 0,int cost = 0, int c = 0,int f = 0):n(n),cost(cost),c(c),f(f){}
  bool operator < (const State &s) const{ return cost > s.cost;}
};

int main(){
  int i,j;
  while(1){
    int G[101][101],c,n,m,s,t;
    State d[101][11];
    priority_queue<State> PQ;

    cin >> c >> n >> m >> s >> t;
    if(c == 0 && n == 0 && m == 0 && s == 0 && t == 0) break;

    for(i=0;i<=n;i++){
      for(j=0;j<=n;j++) G[i][j] = INF;
      for(j=0;j<=c;j++){
	d[i][j].cost = INF;
	d[i][j].n = i;
	d[i][j].c = j;
	d[i][j].f = 0;
      }
    }

    for(i=0;i<m;i++){
      int a,b,c;
      cin >> a >> b >> c;
      G[a][b] = G[b][a] = c;
    }

    d[s][c].cost = 0;
    State p = d[s][c];
    PQ.push(p);

    while(!PQ.empty()){
      p = PQ.top();
      PQ.pop();
      d[p.n][p.c].f = 1;

      for(i=0;i<=n;i++){
	if(d[i][p.c].f == 0 && G[p.n][i] + p.cost < d[i][p.c].cost){
	  d[i][p.c].cost = G[p.n][i] + p.cost;
	  PQ.push(d[i][p.c]);
	}
	if(p.c > 0 && G[p.n][i] != INF && d[i][p.c-1].f == 0 && G[p.n][i] / 2 + p.cost < d[i][p.c-1].cost){
	  d[i][p.c-1].cost = G[p.n][i] / 2 + p.cost;
	  PQ.push(d[i][p.c-1]);
	}
      }
    }

    int min = INF;
    for(i=0;i<=c;i++){
      if(min > d[t][i].cost) min = d[t][i].cost;
    }
    cout << min << endl;

  }
  return 0;
}

//0212