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 <bits/stdc++.h>
#define F first
#define S second
#define INF 1<<26
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>PP;
typedef struct{
  int to,cost;
}Edge;
int main(){
  int c,n,m,st,go;
  while(1){
    int d[11111][111];
    cin >> c >> n >> m >> st >> go;
    if(c==0 && n==0 && m==0 && st==0 && go==0)break;
    for(int i=0;i<=m;i++){
      for(int j=0;j<=c;j++){
	d[i][j]=INF;
      }
    }
    st--;go--;
    
    int a,b,f;
    vector<Edge> G[1111];
    for(int i=0;i<m;i++){
      cin >> a >> b >> f;
      a--;b--;
      G[a].push_back((Edge){b,f});
      G[b].push_back((Edge){a,f});
    }
    priority_queue<PP,vector<PP>,greater<PP> >pq;
    pq.push(PP(0,P(st,c)));
    d[st][c]=0;
    while(!pq.empty()){
      PP p=pq.top();//左から、コスト、今いる場所、残りのチケット
      pq.pop();
      int now=p.S.F;//今いる場所
      int ti=p.S.S;//チケット
      for(int i=0;i<G[now].size();i++){
	Edge e=G[now][i];
	if(ti){//チケットがあったら
	  if(d[e.to][ti-1] > d[now][ti]+(e.cost/2)){
	    d[e.to][ti-1]=d[now][ti]+(e.cost/2);
	    pq.push(PP(d[e.to][ti-1],P(e.to,ti-1)));
	  }
	}
	if(d[e.to][ti] > d[now][ti]+e.cost){
	  d[e.to][ti]=d[now][ti]+e.cost;
	  // cout << d[e.to][ti] << endl;
	  pq.push(PP(d[e.to][ti],P(e.to,ti)));
	}
      } 
    }
    
    int ans=INF;
    for(int i=0;i<=c;i++){
      ans=min(ans,d[go][i]);
    }
    cout << ans << endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <cstring>
#include <string>
#include <sstream>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<int> > table;

int n;
const int INF = (int)1e7;
const int N = 100;
const int C = 11;
table cost(N);
vector<vector<bool> > used(11);

int dijkstra(int, int, int);

int main(void){
    rep(i, N) cost[i].resize(N);
    rep(i, C) used[i].resize(N);

    for(int c, m, s, g; cin >> c >> n >> m >> s >> g, n; cout << dijkstra(s, g, c) << endl){
        rep(i, N) fill(ALL(cost[i]), INF);
        rep(i, C) fill(ALL(used[i]), false);

        while(m --){
            int a, b, f; cin >> a >> b >> f;
            
            cost[a - 1][b - 1] = cost[b - 1][a - 1] = f;
        }
    }
    
    return 0;
}

int dijkstra(int s, int g, int c){
    table d(c + 1);
    rep(i, c + 1) d[i].resize(n), fill(ALL(d[i]), INF);
    
    d[c][s - 1] = 0;

    while(1){
        int vn = -1, vc = -1;

        rep(i, c + 1) rep(j, n) if(!used[i][j] && (vc == -1 || d[i][j] < d[vc][vn])) vc = i, vn = j;

        if(vc == -1) break;
        used[vc][vn] = true;

        rep(u, n){
            d[vc][u] = min(d[vc][u], d[vc][vn] + cost[vn][u]);
            if(vc) d[vc - 1][u] = min(d[vc - 1][u], d[vc][vn] + cost[vn][u] / 2);
        }
    }

    int ret = INF;
    rep(i, c) ret = min(ret, d[i][g - 1]);
    return ret;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pp;

const int INF = 1e9;

double EPS = 1e-10;


int c, n, m, s, g;



const int MAX_V = 510;

int d[MAX_V][MAX_V][15];
int connect[MAX_V][MAX_V];
int V;
 
void warshall_floyd_init(){
	for(int i = 0; i < V; i++){
		for(int j = 0; j < V; j++){
			for(int k = 0; k <= c; k++){
				if(i == j) d[i][i][k] = 0;
				else d[i][j][k] = INF;
			}
			connect[i][j] = 0;
		}
	}
}

void warshall_floyd() {
				for(int l = c; l>=0; l--){
				//for(int l = 0; l <= c; l++){
	for (int k = 0; k < V; k++) {
		for (int i = 0; i < V; i++) {
			for (int j = 0; j < V; j++) {
					d[i][j][l] = min({d[i][j][l], d[i][k][l] + d[k][j][c], d[i][k][c] + d[k][j][l]});
					if(l>0 && connect[k][j] > 0){
						d[i][j][l-1]=min(d[i][j][l-1], d[i][k][l]+connect[k][j]/2);
					}
					if(l>0 && connect[i][k] > 0){
						d[i][j][l-1]=min(d[i][j][l-1],connect[i][k]/2 + d[k][j][l]);						
					}
				}
			}
		}
	}
}
int main(){
	int a, b, f;
	int ans;
	while(cin>>c>>n>>m>>s>>g){
		if(c == 0 && n == 0 && m == 0 && s == 0 && g == 0) break;
		s--; g--;
		V = n;
		warshall_floyd_init();
		//cout<<d[0][2][0]<<endl;
		for(int i = 0; i < m; i++){
			cin>>a>>b>>f;
			//f/=10;
			a--; b--;
			//d[a][b][c] = d[b][a][c] = f;
			d[a][b][c] = min(d[a][b][c], f);
			d[b][a][c] = min(d[b][a][c], f);
			connect[a][b] = connect[b][a] = f;	
		}
		warshall_floyd();
		int ans = INF;
		for(int i = 0; i <= c; i++) ans = min(ans, d[s][g][i]);
		cout<<ans<<endl;
		//cout<<" "<<d[4][5][2]<<endl;
	}
	
}