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<algorithm>
#include<queue>
#include<vector>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;// F -> to, S -> cost
typedef pair<P,int> PP;// F->P(to,cost), S->discount
int c,n,m,s,d;
vector<PP> vec[1000];
int MD[1000][13];
const int INF = 1<<29;

void dijkstra(){
  priority_queue<PP,vector<PP>,greater<PP> > que;
  rep(i,n+1)rep(j,13)MD[i][j] = INF;
  //syokika
  MD[s][c] = 0;
  que.push(PP(P(0,s),c));//dis,start,discount

  while(!que.empty() ){
    PP p = que.top();que.pop(); //priority_queのPPと
    int v = p.F.S;
    
    for(int i=0;i<vec[v].size();i++){
      PP po = vec[v][i]; //vectorのPPは意味が違うので注意！！！
      //if(MD[v][po.S] < po.F.S)continue;
      if(MD[po.F.F][c] > p.F.F + po.F.S){
	MD[po.F.F][c] = p.F.F+po.F.S;
	que.push(PP(P(MD[po.F.F][c],po.F.F),c));
      }
      if(po.S > 0 && MD[po.F.F][p.S-1] > p.F.F + po.F.S/2 ){
	MD[po.F.F][p.S-1] = p.F.F+po.F.S/2;
	que.push(PP(P(MD[po.F.F][p.S-1],po.F.F),p.S-1));
	vec[v][i].S--;
      }
    }
  }
}


int main(){
  int x,y,co;
  while(true){
    cin >> c >> n >> m >> s >> d;
    if(c+n+m+s+d == 0)break;
    rep(i,1000)vec[i].clear();
    rep(i,m){
      cin >> x >> y >> co;
      vec[x].push_back(PP(P(y,co),c));
      vec[y].push_back(PP(P(x,co),c));
    }
    dijkstra();
    int ans = INF;
    for(int i=0;i<=c;i++){
      ans = min(ans,MD[d][i]);
    }
    cout << ans << endl;
  }
  return 0;
}

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

#define INF 1111111111
#define F first
#define S second

struct edge {
  int to, cost;
  edge(int _to, int _cost) {to = _to; cost=_cost;}
};
typedef pair<int, pair<int, int> > P;

vector<edge> G[512];
int d[16][512];
int c, n, m, s, g;

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d[0], d[0] + 16 * 512, INF);
  d[c][s] = 0;
  que.push(P(0, pair<int, int>(s, c)));
  while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.S.F; int w = p.S.S;
    if(d[w][v] < p.F) continue;
    for(int i = 0;i < G[v].size(); i++){
      edge e = G[v][i];
      if(d[w][e.to] > d[w][v] + e.cost){
        d[w][e.to] = d[w][v] + e.cost;
        que.push(P(d[w][e.to], pair<int, int>(e.to, w)));
      }
      if(w > 0 && d[w - 1][e.to] > d[w][v] + e.cost / 2){
	d[w - 1][e.to] = d[w][v] + e.cost / 2;
	que.push(P(d[w - 1][e.to], pair<int, int>(e.to, w - 1)));
      }
    }
  }
}

int main(void){
  int a, b, f;
  for( ; ; ){
    for(int i = 0;i < 512; i++) G[i].clear();
    scanf("%d %d %d %d %d", &c, &n, &m, &s, &g);
    if(!(c + n + m + s + g)) break;
    for(int i = 0;i < m; i++){
      scanf("%d %d %d", &a, &b, &f);
      G[a].push_back(edge(b,f));
      G[b].push_back(edge(a,f));
    }
    
    dijkstra(s);
    int ans = INF;
    for(int i = 0;i <= c; i++) ans = min(ans, d[i][g]);
    printf("%d\n", ans);
  }
}

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

using namespace std;

#define INF 100000000

struct edge {
	int to, cost;
};

int main() {
	int c, n, m, s, d;
	while (cin >> c >> n >> m >> s >> d) {
		if (c == 0 && n == 0 && m == 0 && s == 0 && d == 0) {
			break;
		}
		vector<edge> ff[101];
		vector< vector<int> > ddd(n+1, vector<int>(n+1, INF));
		int a, b, f;
		for (int i = 0; i < m; i++) {
			cin >> a >> b >> f;
			edge e;
			e.to = b;
			e.cost = f;
			ff[a].push_back(e);
			e.to = a;
			ff[b].push_back(e);
			ddd[a][b] = ddd[b][a] = f;
		}
		for (int i = 1; i <= n; i++) {
			ddd[i][i] = 0;
		}
		for (int k = 1; k <= n; k++) {
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					ddd[i][j] = min(ddd[i][j], ddd[i][k]+ddd[k][j]);
				}
			}
		}
		vector<int> isd[101];
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (ddd[i][j] != INF) {
					isd[i].push_back(j);
				}
			}
		}
		vector< vector< vector<int> > > dp(n+1, vector< vector<int> >(n+1, vector<int>(c+1, INF)));
		for (int i = 1; i <= n; i++) {
			dp[s][i][0] = ddd[s][i];
		}
		for (int k = 1; k <= c; k++) {
			for (int p = 1; p <= n; p++) {
				dp[s][p][k] = dp[s][p][k-1];
				for (int i = 0; i < isd[s].size(); i++) {
					int ii = isd[s][i];
					for (int j = 0; j < isd[ii].size(); j++) {
						int jj = isd[ii][j];
						for (int q = 0; q < ff[jj].size(); q++) {
							int qq = ff[jj][q].to;
							if (ddd[qq][p] == INF) continue;
							if (dp[s][p][k] > dp[s][ii][k-1]+ddd[ii][jj]+(ff[jj][q].cost/2)+ddd[qq][p]) {
								dp[s][p][k] = dp[s][ii][k-1]+ddd[ii][jj]+(ff[jj][q].cost/2)+ddd[qq][p];
							}
						}
					}
				}
			}
		}
		cout << dp[s][d][c] << endl;
	}
	return 0;
}