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 <list>
#include <queue>
#include <map>

using namespace std;

struct node
{
	int ticket, si;
	int cost;
	bool det;
};

struct comparator : public binary_function<node *, node *, bool>
{
	bool operator() (node *x, node *y) const { return x->cost > y->cost; }
};

typedef pair<int, int> edge_t;
typedef list<edge_t> edgelist_t;

static node nodes[11][101];
static map<int, edgelist_t > edges;

int main()
{
	int C,N,M,S,D;
	while(cin>>C>>N>>M>>S>>D, C&&N&&S&&M&&D)
	{
		for (int c = 0; c <= C; c++)
		{
			for (int i = 1; i <= N; i++)
			{
				nodes[c][i].ticket = c;
				nodes[c][i].si = i;
				nodes[c][i].cost = 1 << 16;
				nodes[c][i].det = false;
			}
		}

		edges.clear();
		for (int i = 0; i < M; i++)
		{
			int a,b,f;
			cin>>a>>b>>f;
			edges[a].push_back(make_pair(b, f));
			edges[b].push_back(make_pair(a, f));
		}

		// Dijkstra
		priority_queue<node *, vector<node *>, comparator> queue;
		nodes[C][S].cost = 0;
		queue.push(&nodes[C][S]);

		int min_cost = 1 << 16;
		while (!queue.empty())
		{
			node *n = queue.top();
			queue.pop();
			if (n->det) continue;
			n->det = true;

			if (n->si == D) min_cost = min(min_cost, n->cost);

			edgelist_t &l = edges[n->si];
			edgelist_t::const_iterator it;
			for (it = l.begin(); it != l.end(); ++it)
			{
				node *n2 = &nodes[n->ticket][(*it).first];
				int cost = (*it).second;

				if (!n2->det)
				{
					n2->cost = min(n2->cost, n->cost + cost);
					queue.push(n2);
				}
				if (n->ticket > 0)
				{
					n2 = &nodes[n->ticket - 1][(*it).first];
					cost = (*it).second / 2;
					if (!n2->det)
					{
						n2->cost = min(n2->cost, n->cost + cost);
						queue.push(n2);
					}
				}
			}
		}
		cout << min_cost << endl;
	}
	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<101;i++)
    for(int j=0;j<11;j++)
      minCost[i][j]=INF;

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

    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)));
      }
    }
  }
  int ans=INT_MAX;
  for(int i=0;i<11;i++)
    ans=min(minCost[d][i],ans);

  return ans;
}

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<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#define fr first
#define sc second
using namespace std;
#define INF 10000000
typedef pair<int,int> iiP;
typedef pair<int,iiP> P;
struct edge{
  int to,cost;
  edge(){}
  edge(int to,int cost):to(to),cost(cost){};
};
int c,n,m;
int S,G;
int min_cost[101][10];
bool used[101][10];
vector< vector<edge> > info;
int solve();
int main(){
  while(cin >> c >> n >> m >> S >> G && (c||n||m||S||G)){
  for(int i=0;i<=n;i++){
    for(int j=0;j<=c;j++){
      min_cost[i][j] = INF;
      used[i][j] = false;
    }
  }
  info.resize(n + 1);
  for(int i=0,a,b,f;i<m;i++){
    cin >> a >> b >> f;
    info[a].push_back(edge(b,f));
    info[b].push_back(edge(a,f));
  }
  cout << solve() << endl;

  info.clear();
  }
}
int solve(){
  priority_queue< P,vector<P>,greater<P> > que;

  min_cost[S][c] = 0;
  que.push(P(0,iiP(S,c)));

  while(!que.empty()){
    P p = que.top();
    int cost = p.fr,now = p.sc.fr,KEN = p.sc.sc;
    que.pop();

    if( now == G) return cost;

    if( used[now][KEN] ) continue;
    used[now][KEN] = true;

    for(int i = 0,l = info[now].size();i < l;i++){
      edge e = info[now][i];
      if(cost + e.cost < min_cost[e.to][KEN]){
        min_cost[e.to][KEN] = cost + e.cost;
        que.push(P(min_cost[e.to][KEN],iiP(e.to,KEN)));
      }
      if(KEN != 0){
        if( cost + e.cost/2 < min_cost[e.to][KEN-1] ){
          min_cost[e.to][KEN-1] = cost + e.cost/2;
          que.push(P(min_cost[e.to][KEN-1],iiP(e.to,KEN-1)));
        }
      }
    }
  }
}