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 <queue>
#include <tuple>

using namespace std;

const int INF = 1<<28;
int c, n, m, s, d;
vector<pair<int, int> > g[100];
int dist[100][11];

typedef tuple<int, int, int> node;

int dijkstra() {
  priority_queue<node, vector<node>, greater<node> > Q;
  Q.push(make_tuple(0, s, c));
  dist[s][c] = 0;
  
  while (!Q.empty()) {
    int cost;
    int v;
    int t;
    tie(cost, v, t) = Q.top();
    Q.pop();

    if (cost > dist[v][t])
      continue;
    
    for (auto &edge: g[v]) {
      int w = edge.first;
      int weight = edge.second;
      if (cost + weight < dist[w][t]) {
        dist[w][t] = cost + weight;
        Q.push(make_tuple(dist[w][t], w, t));
      }
      if (t > 0 && cost + weight/2 < dist[w][t-1]) {
        dist[w][t-1] = cost + weight/2;
        Q.push(make_tuple(dist[w][t-1], w, t-1));
      }
    }
  }

  int ret = INF;
  for (int i = 0; i < 11; i++)
    ret = min(ret, dist[d][i]);
  return ret;
}

void init() {
  for (int i = 0; i < 100; i++)
    g[i].clear();
  for (int i = 0; i < 100; i++)
    for (int j = 0; j < 11; j++)
      dist[i][j] = INF;
}

int main(int argc, char *argv[])
{
  for (;;) {
    cin >> c >> n >> m >> s >> d;
    if (!c && !n && !m && !s && !d)
      break;
    --s, --d;
    init();
    for (int i = 0; i < m; i++) {
      int a, b, f;
      cin >> a >> b >> f;
      --a, --b;
      g[a].push_back(make_pair(b, f));
      g[b].push_back(make_pair(a, f));
    }
    int ret = dijkstra();
    printf("%d\n", ret);
  }
  
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<climits>

using namespace std;

typedef pair<int,pair<int,int> >P;

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

int minCost[101][11];
vector<Edge> edge[101];
static const int INF = INT_MAX;

int c,n,m,s,d;

int dijkstra(void){
  priority_queue<P, vector<P>, greater<P> >que;
  que.push(make_pair(0,make_pair(s,c)));

  for(int i=0;i<=n;i++)
    for(int j=0;j<=n;j++)
      minCost[i][j]=INF;

  while(!que.empty()){
    P p = que.top();
    que.pop();

    if(p.second.first==d)return p.first;
    
    for(int i=0;i<edge[p.second.first].size();i++){
      Edge e = edge[p.second.first][i];
      if(p.first+e.cost < minCost[e.to][p.second.second]){
	minCost[e.to][p.second.second] = p.first+e.cost;
	que.push(make_pair(p.first+e.cost,make_pair(e.to,p.second.second)));
      }
    }
    
    if(p.second.second==0)continue;
    
    for(int j=0;j<edge[p.second.first].size();j++){
      Edge e = edge[p.second.first][j];
      if(p.first+e.cost/2 < minCost[e.to][p.second.second-1]){
	minCost[e.to][p.second.second-1] = p.first+e.cost/2;
	que.push(make_pair(p.first+e.cost/2,make_pair(e.to,p.second.second-1)));
      }
    }
  }
  return -1;
}

int main(void){
  int a,b,f;

  while(cin >> c >> n >> m >> s >> d,c|n|m|s|d){

    for(int i=0;i<=n;i++)edge[i].clear();

    for(int i=0;i<m;i++){
      cin >> a >> b >> f;
      edge[a].push_back(Edge(b,f));
      edge[b].push_back(Edge(a,f));
    }

    cout << dijkstra() << endl;
  }

  return 0;
}

C++: #include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;

int C;

// dijkstra O(ElogV)
// verify : https://onlinejudge.u-aizu.ac.jp/problems/GRL_1_A
template<typename T>
struct Dijkstra {
private:
    int V;
    struct edge { int to; T cost; };
    vector<vector<edge>> G;
public:
    const T inf = numeric_limits<T>::max();

    // s から i の最小コスト
    // 経路がない場合は inf
    vector<vector<T>> d;

    Dijkstra(int V) : V(V) {
        G.resize(V);
    }

    // 辺の追加
    // 有向の場合　directed = true
    void add_edge(int from, int to, T weight, bool directed = false) {
        G[from].push_back({to,weight});
        if (!directed) G[to].push_back({from,weight});
    }

    void build(int s) {
        d.assign(V, vector<T>(C+1,inf));
        typedef pair<pair<T,int>, int> P; //(cost,v)
        priority_queue<P, vector<P>, greater<P>> pq;
        d[s][0] = 0;
        pq.push(P({d[s][0],0}, s));
        while (!pq.empty()) {
            P p = pq.top(); pq.pop();
            int v = p.second;
            int c = p.first.first;
            int k = p.first.second;
            if (d[v][k] < c) continue;
            for (const edge &e : G[v])
            {
                // 最小値が更新されるとき push
                if (k < C && d[e.to][k+1] > d[v][k] + e.cost / 2) {
                    d[e.to][k + 1] = d[v][k] + e.cost / 2;
                    pq.push({{d[e.to][k + 1],k + 1}, e.to});
                }
                if (d[e.to][k] > d[v][k] + e.cost) {
                    d[e.to][k] = d[v][k] + e.cost;
                    pq.push({{d[e.to][k],k}, e.to});
                }
            }
        }
    }
};

int main() {
    while (true) {
        int n, m, s, d; cin >> C >> n >> m >> s >> d;
        if (!C) break;
        Dijkstra<ll> G(n);
        s--; d--;
        REP(i, m) {
            int a, b; ll c; scanf("%d %d %lld", &a, &b, &c);
            a--; b--;
            G.add_edge(a, b, c);
        }
        G.build(s);
        ll ans = LLINF;
        REP(i, C+1) {
            ans = min(ans, G.d[d][i]);
        }
        cout << ans << endl;
    }
    return 0;
}