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>
using namespace std;

const double PI = acos(-1);
const double EPS = 1e-15;
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
const ll MOD1 = 998244353;
typedef pair<int,int> P;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define mp make_pair

int main(){
  int c,n,m,s,d;
  while (cin >> c >> n >> m >> s >> d,c,n,m,s,d) {
    ll dp[110][11];
    REP(i,110) REP(j,11) dp[i][j] = INF;
    s--;
    d--;
    vector<pair<int,ll>> G[110];
    REP(i,m) {
      int a,b;
      ll f;
      cin >> a >> b >> f;
      a--;
      b--;
      G[a].pb({b,f});
      G[b].pb({a,f});
    }
    priority_queue<pair<ll,pair<int,int>>,vector<pair<ll,pair<int,int>>>,greater<pair<ll,pair<int,int>>>> pq;
    dp[s][0] = 0;
    pq.push({0,{s,0}});
    while (!pq.empty()) {
      pair<ll,pair<int,int>> tp = pq.top();
      //cout << tp.fi << " " << tp.se.fi << " " << tp.se.se << endl;
      pq.pop();
      int point = tp.se.fi;
      int ticket = tp.se.se;
      if (tp.fi > dp[point][ticket]) continue;
      //cout << "test" << endl;
      REP(i,sz(G[point])) {
        int next = G[point][i].fi;
        ll cost = G[point][i].se;
        if (dp[point][ticket] + cost < dp[next][ticket]) {
          dp[next][ticket] = dp[point][ticket] + cost;
          pq.push({dp[next][ticket],{next,ticket}});
        }
        if (ticket < c && dp[point][ticket] + cost/2 < dp[next][ticket+1]) {
          dp[next][ticket+1] = dp[point][ticket] + cost/2;
          pq.push({dp[next][ticket+1],{next,ticket+1}});
        }
      }
    }
    ll ans = INF;
    REP(i,c+1) {
      ans = min(ans,dp[d][i]);
    }
    cout << dp[d][c] << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;

class edge{
	public:
		int to,cost;
		edge();
		edge(int _to,int _cost){
			to = _to;
			cost = _cost;
		}
};
class state{
	public:
		int id,cost,ticket;
		state();
		state(int _id,int _cost,int _ticket){
			id = _id;
			cost = _cost;
			ticket = _ticket;
		}
		bool operator<(const state st)const{
			return cost > st.cost;
		}
};
const int INF = 1000000000;

int main()
{
	int c,n,m,s,g;
	while(cin >> c >> n >> m >> s >> g){
		if(!c&&!n&&!m&&!s&&!g)
			break;
		vector<edge> t[101];
		int d[101][11];
		for(int i=0;i<m;i++){
			int a,b,cost;
			cin >> a >> b >> cost;
			a--;b--;
			t[a].push_back(edge(b,cost));
			t[b].push_back(edge(a,cost));
		}
		s--;g--;

		int ans = INF;
		for(int j=0;j<101;j++){
			for(int i=0;i<11;i++){
				d[j][i] = INF;
			}
		}
		d[s][c] = 0;
		priority_queue<state> que;
		que.push(state(s,0,c));
		while(!que.empty()){
			state st = que.top();
			que.pop();
			int v = st.id;
			if(st.id == g)
				ans = min(ans,st.cost);
			for(unsigned i=0;i<t[v].size();i++){
				edge e = t[v][i];	
				if( d[e.to][st.ticket] > d[v][st.ticket] + e.cost){
					d[e.to][st.ticket] = d[v][st.ticket] + e.cost;
					que.push(state(e.to,d[e.to][st.ticket],st.ticket));
				}
				if(st.ticket>0){
					if( d[e.to][st.ticket-1] > d[v][st.ticket] + (e.cost)/2){
						d[e.to][st.ticket-1] = d[v][st.ticket] + (e.cost)/2;
						que.push(state(e.to,d[e.to][st.ticket-1],st.ticket-1));
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define Rrep(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int c, n, m, s, d;
int a, b, f;
struct edge {int to, cost;};
vector<edge> G[105];
vector<vector<int> > dp(11, vector<int>(105, 0));

void dijkstra(int s, int a) {
	priority_queue<P, vector<P>, greater<P> > que;
	rep(i, 105) dp[a][i] = INF;
	dp[a][s] = 0;
	que.push(P(0, s));

	while(!que.empty()) {
		P p = que.top(); que.pop();
		int tmp = p.second;
		if(dp[a][tmp] < p.first) continue;
		rep(i, G[tmp].size()) {
			int to = G[tmp][i].to;
			int cost = (a == 0) ? G[tmp][i].cost + dp[a][tmp] : min(G[tmp][i].cost + dp[a][tmp], G[tmp][i].cost / 2 + dp[a - 1][tmp]);
			if(dp[a][to] > cost) {
				dp[a][to] = cost;
				que.push(P(-cost, to));
			}
		}
	}

}

int main() {
	while(scanf("%d %d %d %d %d", &c, &n, &m, &s, &d)) {
		s--; d--;
		if(c == 0) return 0;
		rep(i, m) {
			scanf("%d %d %d", &a, &b, &f); 
			a--; b--;
			G[a].push_back((edge){b, f});
			G[b].push_back((edge){a, f});
		}
		int ans = INF;
		rep(i, c + 1) dijkstra(s, i);
		printf("%d\n", dp[c][d]);

		rep(i, 105){
      		G[i].erase(G[i].begin(), G[i].end());
    	}
    	rep(i, 11){
      		dp[i].erase(dp[i].begin(), dp[i].end());
    	}
	}
	return 0;
}