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 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;
  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++){
      for(int j=0;j<MAX_V;j++){
	min_cost[i][j] = INF;
      }
    }
    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 <bits/stdc++.h>
//#include <math.h>
using namespace std;

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
//typedef pair<int,int> P;
//typedef pair<int,P> PP;

//-----------------------------------------------------------------------------

#define INIT INF
typedef int Weight;
typedef pair<Weight,int> P;

typedef pair<P,int> PP;

int c,n,m,s,g;

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

typedef vector< vector<Edge> > Graph;

bool operator<(const Edge &e,const Edge &f) {
	return e.cost!=f.cost?e.cost>f.cost:e.to<f.to;
}

void dijkstra(const Graph &G,int s,vector< vector<Weight> > &dist) {
	int n=(int)G.size();
	dist.assign(n,vector<Weight>(c+1,INIT));
	dist[s][0]=0;
	priority_queue< PP,vector<PP>,greater<PP> > Q;
	Q.push(PP(P(0,s),0));
	while(!Q.empty()) {
		PP p=Q.top();Q.pop();
		int v=p.first.second,times=p.second;
		if(dist[v][times]<p.first.first) continue;
		for(auto e:G[v]) {
			if(dist[e.to][times]>dist[v][times]+e.cost) {
				dist[e.to][times]=dist[v][times]+e.cost;
				Q.push(PP(P(dist[e.to][times],e.to),times));
			}
			if(times+1<=c&&dist[e.to][times+1]>dist[v][times]+e.cost/2) {
				dist[e.to][times+1]=dist[v][times]+e.cost/2;
				Q.push(PP(P(dist[e.to][times+1],e.to),times+1));
			}
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin>>c>>n>>m>>s>>g;
	s--,g--;
	Graph G(n);
	vector< vector<Weight> > dist(n,vector<Weight>(c+1));
	REP(i,m) {
		int a,b;Weight c;
		cin>>a>>b>>c;
		a--,b--;
		G[a].emplace_back(b,c);
		G[b].emplace_back(a,c);
	}
	dijkstra(G,s,dist);
	Weight ans=INIT;
	REP(i,c+1) ans=min(ans,dist[g][i]);
	cout<<ans<<endl;

	return 0;
}

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

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

struct edge {
    int to, cost;
};

struct state {
    int v, d, rest;
    bool operator<(const state& s)const{
        return d>s.d;
    }
};

int dijk(int s, int g, vector<vector<edge>> G, int c){

    vector<int> d(G.size(), 1 << 30);
    d[s] = 0;
    priority_queue<state> q;
    q.push({ s, 0, c });

    while (q.size()){
        state sta = q.top();
        q.pop();

        int v = sta.v;

        if (d[v] > sta.d) continue;

        int rest = sta.rest;
        rep(i, G[v].size()){
            int to = G[v][i].to;
            int cost = G[v][i].cost;

            if (d[to] > sta.d + cost){
                d[to] = sta.d + cost;
                q.push({ to, sta.d + cost, rest});
            }

            if (!!rest && d[to] > sta.d + cost/2){
                d[to] = sta.d + cost / 2;
                q.push({ to, sta.d + cost / 2, rest - 1 });
            }
        }
    }
    return d[g];
}

int main(){
    while (1){
        int c, V, E, s, d;
        cin >> c >> V >> E >> s >> d;
        if (V == 0) break;
        vector<vector<edge>> G(V);
        s--; d--;
        rep(i, E){
            int a, b, c;
            cin >> a >> b >> c;
            a--; b--;
            G[a].push_back({ b, c });
            G[b].push_back({ a, c });
        }
        cout << dijk(s, d, G, c) << endl;
    }
}