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 <vector>
#include <utility>
#include <queue>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
struct Edge{ int to, cost; };
vector<Edge> G[101];
int dist[11][101];
const int INF = (1<<28);
int dijkstra( int s, int a ){
  priority_queue< P, vector<P>, greater<P> > q;
  for( int j=0; j<=100; j++ )
    dist[a][j] = INF;
  dist[a][s] = 0;
  q.push({ 0, s });
  while( !q.empty() ){
    int cost = q.top().first;
    int v = q.top().second;
    q.pop();
    if( dist[a][v] < cost ) continue;
    for( auto it=G[v].begin(); it!=G[v].end(); ++it ){
      int d = dist[a][v] + it->cost;
      if( a > 0 )
        d = min( d, dist[a-1][v] + it->cost/2 );
      if( dist[a][it->to] > d ){
        dist[a][it->to] = d;
        q.push({ d, it->to });
      }
    }
  }
  //for( int i=1; i<=3; i++ )
  //  cout << dist[a][i] << ' '; cout << endl;
}
int main( void ){
  while( 1 ){
    int c,n,m,s,d,a,b,f;
    cin >> c >> n >> m >> s >> d;
    if( c == 0 ) break;
    for( int i=1; i<=n; i++ ) G[i].clear();
    for( int i=0; i<m; i++ ){
      cin >> a >> b >> f;
      G[a].push_back({ b, f });
      G[b].push_back({ a, f });
    }
    for( int i=0; i<=c; i++ )
      dijkstra( s, i );
    cout << dist[c][d] << endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <cassert>
#include <algorithm>
using namespace std;
typedef pair<int, int> edge;
struct state{
  int cost, coupon, station;
  state(int cost_, int coupon_, int station_):cost(cost_), coupon(coupon_), station(station_){}
  bool operator> (const state &s) const{
    if(cost == s.cost){
      return coupon < s.coupon;
    }
    return cost > s.cost;
  }
};
int djikstra(vector<vector<edge> > graph, int start, int goal, int coupon){
  priority_queue<state, vector<state>, greater<state> > pq;
  pq.push(state(0, coupon, start));
  bool visited[coupon][graph.size()];
  fill_n((bool*)visited, (coupon+1) * graph.size(), false);
  while(!pq.empty()){
    state cur = pq.top(); pq.pop();
    if(visited[cur.coupon][cur.station]){
      continue;
    }
    if(cur.station == goal){
      return cur.cost;
    }
    visited[cur.coupon][cur.station] = true;
    for(int i = 0; i < graph[cur.station].size(); ++i){
      int to = graph[cur.station][i].first;
      int c = graph[cur.station][i].second;
      if(cur.coupon > 0){
        pq.push(state(cur.cost+c/2, cur.coupon-1, to));
      }
      pq.push(state(cur.cost+c, cur.coupon, to));
    }
  }
  assert(false);
}
int main(){
  int c, n, m, s, d;
  while(true){
    cin >> c >> n >> m >> s >> d;
    if((c|n|m|s|d) == 0){
      break;
    }
    vector<vector<edge> > graph(n+1, vector<edge>());
    for(int i = 0; i < m; ++i){
      int a, b, f;
      cin >> a >> b >> f;
      graph[a].push_back(make_pair(b, f));
      graph[b].push_back(make_pair(a, f));
    }
    cout << djikstra(graph, s, d, c) << endl;
  }
  return 0;
}

C++: #include <map>
#include <vector>
#include <cstdio>
using namespace std;
int cost[101][11];
int main(){
	int c,N,m,s,d,i,j,k,x;
	for(;scanf("%d%d%d%d%d",&c,&N,&m,&s,&d),N;){
		vector<map<int,int> >dist(N+1);
		memset(cost,99,sizeof(cost));
		for(k=0;k<m;k++){
			scanf("%d%d%d",&i,&j,&x);dist[i][j]=dist[j][i]=x;
		}
		for(i=0;i<=c;i++)cost[s][i]=0;
		for(;~c;c--){
			vector<bool>used(N+1);
			for(;;){ //dijkstra
				int m=9999999;
				for(i=0;i<N;i++)if(!used[i]&&m>cost[i][c])m=cost[i][c];
				if(m==9999999)break;
				for(j=0;j<N;j++)if(m==cost[j][c]){
					map<int,int>::iterator it=dist[j].begin();
					for(used[j]=1;it!=dist[j].end();it++){
						if(cost[it->first][c]>it->second+cost[j][c])cost[it->first][c]=it->second+cost[j][c];
						if(c&&cost[it->first][c-1]>it->second/2+cost[j][c])cost[it->first][c-1]=it->second/2+cost[j][c];
					}
				}
			}
		}
		printf("%d\n",cost[d][0]);
	}
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<queue>
#include<map>
#define P pair<int,int>
using namespace std;

struct K {
	int basho, nokori, mincost;
};
bool operator<(K a, K b) {
	return a.mincost > b.mincost;
}
int main() {
	int cost[100][11];//n???????????°????????§m????????????????°????
	int B, c, d, e, f;
	while (scanf("%d%d%d%d%d", &B, &c, &d, &e, &f), B || c || d || e || f) {
		vector<P>a[100]{};
		memset(cost, 0x3f, sizeof(cost));
		e--; f--; cost[e][B] = 0;
		priority_queue<K>Q;
		K g;
		g.basho = e; g.nokori = B; g.mincost = 0;
		Q.push(g);
		for (int h = 0; h < d; h++) {
			int i, j, k;
			scanf("%d%d%d", &i, &j, &k);
			i--; j--;
			a[i].push_back(P(k, j));
			a[j].push_back(P(k, i));
		}
		while (Q.size()) {
			K l = Q.top(); Q.pop();
			int m = l.mincost, n = l.nokori, b = l.basho;
			if (cost[b][n] < m)continue;
			for (P o : a[b]) {
				if (cost[o.second][n] > cost[b][n] + o.first) {
					cost[o.second][n] = cost[b][n] + o.first;
					K xx;
					xx.basho = o.second;
					xx.mincost = cost[o.second][n];
					xx.nokori = n;
					Q.push(xx);
				}
				if (n&&cost[o.second][n-1] > cost[b][n] + o.first / 2) {
					cost[o.second][n - 1] = cost[b][n] + o.first / 2;
					K yy;
					yy.basho = o.second;
					yy.nokori = n - 1;
					yy.mincost = cost[o.second][n - 1];
					Q.push(yy);
				}
			}
		}
		int MINCOST = 1 << 29;
		for (int sss = 0; sss < 11; sss++) {
			MINCOST = min(MINCOST, cost[f][sss]);
		}
		cout << MINCOST << endl;
	}
}