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 <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int c,n,m,s,e;
    while(cin>>c>>n>>m>>s>>e,c+n+m+e+s){
        --s,--e;
        vector<vector<pii>>edge(n,vector<pii>());
        rep(i,m){
            int a,b,cost; cin>>a>>b>>cost;
            --a,--b;
            edge[a].push_back(pii(b,cost));
            edge[b].push_back(pii(a,cost));
        }
        typedef  pair<pii,int>piii;
        priority_queue<piii,vector<piii>,greater<piii>>que;
        vector<vector<int>>d(n,vector<int>(11,INF));
        que.push(piii(pii(0,c),s));
        d[s][c]=0;
        while(!que.empty()){
            piii now=que.top(); que.pop();
            if(d[now.second][now.first.second]<now.first.first)continue;
            for(int i=0; i<edge[now.second].size();i++){
                pii next=edge[now.second][i];
                if(d[next.first][now.first.second]>d[now.second][now.first.second]+next.second){
                    d[next.first][now.first.second]=d[now.second][now.first.second]+next.second;
                    que.push(piii(pii(d[next.first][now.first.second],now.first.second),next.first));
                }
                if(now.first.second>0){
                    if(d[next.first][now.first.second-1]>d[now.second][now.first.second]+(next.second)/2){
                        d[next.first][now.first.second-1]=now.first.first+(next.second)/2;
                        que.push(piii(pii(d[next.first][now.first.second-1],now.first.second-1),next.first));
                    }
                }
            }
        }
        int ans=INF;
        for(int i=0; i<=c; i++)cmin(ans,d[e][i]);
        cout<<ans<<endl;
    }
}

C++: #include <bits/stdc++.h>

using namespace std;

#define MAX 120
#define INF 1e9

struct Edge{
  int to,cost;
  Edge(int t,int c) : to(t),cost(c) {}
};

struct State{
  int cost,v,tic;
  State(int c,int v,int t) : cost(c),v(v),tic(t) {}
  bool operator < (const State &s)const{
    return cost > s.cost;
  }
};

int C,V,E,src,dst;
vector<Edge> G[MAX];

int dijkstra(){
  priority_queue<State> Q;
  Q.push(State(0,src,C));
  int dist[MAX][11];
  fill(dist[0],dist[0]+MAX*11,INF);
  dist[src][C] = 0;
  
  while(!Q.empty()){
    State s = Q.top(); Q.pop();
    int v = s.v,t = s.tic;
    if(dist[v][t] < s.cost) continue;
    if(v == dst) return dist[v][t];
    
    for(int i = 0 ; i < (int)G[v].size() ; i++){
      Edge e = G[v][i];
      if(dist[v][t] + e.cost < dist[e.to][t]){
        dist[e.to][t] = dist[v][t] + e.cost;
        Q.push(State(dist[e.to][t],e.to,t));
      }
      if(t > 0){
        if(dist[v][t] + e.cost/2 < dist[e.to][t-1]){
          dist[e.to][t-1] = dist[v][t] + e.cost/2;
          Q.push(State(dist[e.to][t-1],e.to,t-1));
        }
      }
    }
  }
}

int main(){
  while(cin >> C >> V >> E >> src >> dst, C){
    src--; dst--;
    for(int i = 0 ; i < V ; i++){
      G[i].clear();
    }
    for(int i = 0 ; i < E ; i++){
      int a,b,c;
      cin >> a >> b >> c; a--; b--;
      G[a].push_back(Edge(b,c));
      G[b].push_back(Edge(a,c));
    }
    cout << dijkstra() << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define MAX_V 101
using namespace std;

struct edge { 
  int to, cost;
  edge(){}
  edge(int to,int cost):to(to),cost(cost){};
};
typedef pair<int ,int> P;
const int INF = 1 << 30;
int V; //ノードの数
vector<edge> Graph[MAX_V];
int min_cost[11][MAX_V];

int c,m,s,d;
void Dijkstra(int s,int chip){ // s:スタートからの最小コストをmin_costに設定
  priority_queue<P,vector< P >, greater<P> > que;
  fill(min_cost[chip],min_cost[chip] + V,INF);
  min_cost[chip][s] = 0;
  que.push(P(0,s));
  
  while(!que.empty()){
    P p = que.top();que.pop();
    int now = p.second;
    int cost = p.first;
    if(min_cost[chip][now] < cost) continue;
    
    for(int i = 0; i < Graph[now].size(); i++){
      edge e = Graph[now][i];
      int a;
      if(chip == 0){
	a = min_cost[chip][now] + e.cost;
      }else{
	a = min(min_cost[chip][now] + e.cost, min_cost[chip-1][now] + e.cost / 2);
	if(min_cost[chip][e.to] > a){
	  min_cost[chip][e.to] = a;
	  que.push(P(min_cost[chip][e.to], e.to));
	}
      }
    }
  }
}

int main(){
  
  while(cin >> c >> V >> m >> s >> d && (c||V||m||s||d)){
    s--;
    d--;
    
    for(int i=0;i<m;i++){
      int a,b,f;
      cin>>a>>b>>f;
      a--;b--;
      Graph[a].push_back(edge(b,f));
      Graph[b].push_back(edge(a,f));
    }
    
    for(int i=0;i<=c;i++){
      Dijkstra(s,i);
    }

    cout<<min_cost[c][d]<<endl;
    
    for(int i=0;i<MAX_V;i++) Graph[i].clear();
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
#include<vector>
#include<math.h>

int main(){

return 0;
}