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<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[110][12];
vector<Edge> edge[110];
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 minCost[d][0];
}

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<queue>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  unsigned i;
  unsigned a[100][100],b[100][11],c[100][11],m,n,o,u,v,x,y,z;
  priority_queue<pair<unsigned,pair<unsigned,unsigned> >,vector<pair<unsigned,pair<unsigned,unsigned> > >,greater<pair<unsigned,pair<unsigned,unsigned> > > > d;
  while(cin>>m>>n>>o>>u>>v&&m+n+o+u+v){
    u--;
    v--;
    memset(a,-1,sizeof(a));
    for(i=0;i<o;i++){
      int p,q,r;
      cin>>p>>q>>r;
      p--;
      q--;
      a[p][q]=a[q][p]=r;
    }
    memset(b,0,sizeof(b));
    memset(c,-1,sizeof(c));
    c[u][0]=0;
    while(d.empty()==0)
      d.pop();
    d.push(make_pair(0,make_pair(u,0)));
    for(;;){
      z=d.top().first;
      x=d.top().second.first;
      y=d.top().second.second;
      d.pop();
      if(x==v)
	break;
      if(b[x][y]==0){
	b[x][y]=1;
	for(i=0;i<n;i++){
	  if((int)a[x][i]!=-1){
	    d.push(make_pair(z+a[x][i],make_pair(i,y)));
	    if(y<m)
	      d.push(make_pair(z+a[x][i]/2,make_pair(i,y+1)));
	  }
	}
      }
    }
    cout<<z<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) string((s).rbegin(), (s).rend())
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

const int INF = 10000;


class V{
public:
	int total;
	int ticket;
	int to;
};
bool operator>(const V &lh, const V &rh){
	return (lh.total > rh.total);
}


int main(){
	int c, n, m, s, d;

	cin >> c >> n >> m >> s >> d;
	n++;
	vector<vector<int> > fare(n, vector<int>(n, INF));
	rep(i, m){
		int a, b, f;
		cin >> a >> b >> f;
		fare[a][b] = fare[b][a] = f;
	}

	vector<vector<int> > done(c+1, vector<int>(n, 0));	// 確定済みか
	vector<vector<int> > best(c+1, vector<int>(n, INF));	// 最短

	V start;
	start.total = 0;
	start.ticket = 0;
	start.to = s;

	priority_queue<V, vector<V>, greater<V> > q;
	q.push(start);

	while(!q.empty()){
		V p = q.top();
		q.pop();

		if(done[p.ticket][p.to] != 0) continue;
		done[p.ticket][p.to] = 1;
		best[p.ticket][p.to] = p.total;

		rep(i, n){
			if(fare[p.to][i] == INF ) continue;
			V next;
			next.total = best[p.ticket][p.to] + fare[p.to][i];
			next.ticket = p.ticket;
			next.to = i;
			q.push(next);
			if(p.ticket < c){
				next.total = best[p.ticket][p.to] + fare[p.to][i]/2;
				next.ticket = p.ticket+1;
				next.to = i;
				q.push(next);
			}
		}
	}
	//rep(i, c+1){
	//	rep(j, n){
	//		printf("%5d", best[i][j]);
	//	}
	//	cout << endl;
	//}

	cout << best[c][d] << endl;

	return 0;
}

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();
    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;
}