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>
using namespace std;
#include<vector>
#include<queue>
//#include<math.h>
struct crq{
	int cost;
	int ticket;
	int now;

	bool operator > (const crq& p) const{
	return cost > p.cost;
	}
};//cost root que
struct root{
	int s;
	int g;
	int cost;
};




int c;
int n;
int m;
int s;
int d;
int ans;
bool townSearched[100];
int townMin[100][11];

int main(){
	while(cin>>c>>n>>m>>s>>d, c|n|m|s|d){
		vector<root> vr;
		ans=0;
		priority_queue<crq,vector<crq>,greater<crq>> q;
		while(!q.empty())q.pop();
		for(int  i=0;i<100;i++){
			townSearched[i]=false;
			for(int  j=0;j<11;j++)townMin[i][j]=1e8;
		}
		for(int i=0;i<m;i++){
			root r;
			cin>>r.s;
			r.s--;
			cin>>r.g;
			r.g--;
			cin>>r.cost;
			vr.push_back(r);
		}
		townMin[s-1][c]=0;
		crq start;
		start.cost=0;
		start.ticket=c;
		start.now=s-1;

		q.push(start);
		while(1){
			crq crq2=q.top();q.pop();
			if(crq2.now==d-1){
				ans=crq2.cost;
				break;
			}
			

			for(int i=0;i<m;i++){
				if(vr.at(i).s==crq2.now){
					if(!townSearched[vr.at(i).g]&&townMin[vr.at(i).g][crq2.ticket]>crq2.cost+vr.at(i).cost){
						crq add;
						add.cost=crq2.cost+vr.at(i).cost;
						add.ticket=crq2.ticket;
						add.now=vr.at(i).g;
						townMin[vr.at(i).g][crq2.ticket]=crq2.cost+vr.at(i).cost;
						q.push(add);
					}

					if(!townSearched[vr.at(i).g]&&crq2.ticket>0&&townMin[vr.at(i).g][crq2.ticket-1]>crq2.cost+vr.at(i).cost/2){
						crq add;
						add.cost=crq2.cost+vr.at(i).cost/2;
						add.ticket=crq2.ticket-1;
						add.now=vr.at(i).g;
						townMin[vr.at(i).g][crq2.ticket-1]=crq2.cost+vr.at(i).cost/2;
						q.push(add);
					}

				}
				if(vr.at(i).g==crq2.now){
					if(!townSearched[vr.at(i).s]&&townMin[vr.at(i).s][crq2.ticket]>crq2.cost+vr.at(i).cost){
						crq add;
						add.cost=crq2.cost+vr.at(i).cost;
						add.ticket=crq2.ticket;
						add.now=vr.at(i).s;
						townMin[vr.at(i).s][crq2.ticket]=crq2.cost+vr.at(i).cost;
						q.push(add);
					}

					if(!townSearched[vr.at(i).s]&&crq2.ticket>0&&townMin[vr.at(i).s][crq2.ticket-1]>crq2.cost+vr.at(i).cost/2){
						crq add;
						add.cost=crq2.cost+vr.at(i).cost/2;
						add.ticket=crq2.ticket-1;
						add.now=vr.at(i).s;
						townMin[vr.at(i).s][crq2.ticket-1]=crq2.cost+vr.at(i).cost/2;
						q.push(add);
					}

				}
			}
			townSearched[crq2.now]=true;
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<queue>
#include<map>
#define MAX 10000000
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
struct edge{
	int cost,to;
};
typedef pair<int,int> p;
typedef pair<int,p> P;
//`Pbg@»ÝÌ@v
int main(){
	int tic,n,m,s,a,b,g,d[11][101],f;
	//d ticket place
	while(cin>>tic>>n>>m>>s>>g,tic||n||m||s||g){
		s--;g--;
		//tic `Pbg
		//n Ì
		//m ´Ì
		//s¨g
		vector<edge> v[101];
		rep(i,m){
			cin>>a>>b>>f;
			a--;b--;
			edge c;
			c.cost=f;
			c.to=b;v[a].push_back(c);
			c.to=a;v[b].push_back(c);
		}
		rep(i,tic+1)
		rep(j,n){
			if(j==s)
			d[i][j]=0;
			else
			d[i][j]=MAX;
		}
		int nowticket,nowplace,nowsum;
		priority_queue<P,vector<P>,greater<P> > que;
		P now;
		que.push(P(tic,p(s,0)));
		while(!que.empty()){
			now=que.top();
			que.pop();
			nowticket=now.first;
			nowplace=now.second.first;
			nowsum=now.second.second;
			if(nowplace==g){
				cout<<nowsum<<endl;
				break;
			}
			if(d[nowticket][nowplace]<nowsum)
				continue;
			rep(i,(int)v[nowplace].size()){
				edge e=v[nowplace][i];
				if(nowticket>0){
					if(d[nowticket-1][e.to]>e.cost/2+nowsum){
						d[nowticket-1][e.to]=e.cost/2+nowsum;
						que.push(P(nowticket-1,p(e.to,d[nowticket-1][e.to])));
					}
				}
				if(d[nowticket][e.to]>e.cost+nowsum){
						d[nowticket][e.to]=e.cost+nowsum;
						que.push(P(nowticket,p(e.to,d[nowticket][e.to])));
				}
			}
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
typedef pair<int, int> Pii;
typedef pair<int, Pii> Pip;
typedef vector<int> Vi;
const int INF = (1<<25);
const int MAX_V = 101;
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

struct edge {
  int to, cost;
  edge(int _to, int _cost) {
    to = _to; cost = _cost;
  }
};

int V;
vector<edge> G[MAX_V];

int dij(int s, int c, int g) {
  priority_queue<Pip, vector<Pip>, greater<Pip> > q;

  int d[11][101];
  for(int i=0; i<11; i++) {
    for(int j=0; j<101; j++) {
      d[i][j] = INF;
    }
  }

  d[c][s] = 0;
  q.push(Pip(0, Pii(s, c)));

  int result = INF;
  while( !q.empty() ) {
    Pip p = q.top(); q.pop();
    int now_cost = p.fr;
    int v = p.sc.fr;
    int c = p.sc.sc;

    if( v == g ) {
      result = now_cost;
      break;
    }

    for(int i=0; i<G[v].size(); i++) {
      edge e = G[v][i];

      int next_cost = d[c][v] + e.cost;
      if( next_cost < d[c][e.to] ) {
	d[c][e.to] = next_cost;
	q.push(Pip(next_cost, Pii(e.to, c)));
      }
      if( c ) {
	next_cost = d[c][v] + e.cost/2;
	if( next_cost < d[c-1][e.to] ) {
	  d[c-1][e.to] = next_cost;
	  q.push(Pip(next_cost, Pii(e.to, c-1)));
	}
      }
    }
  }
  return result;
}

int main() {
  int c, n, m, s, g;
  while( cin >> c >> n >> m >> s >> g, c || n || m || s || g ) {
    for(int i=0; i<n+1; i++) {
      G[i].clear();
    }
      
    s--; g--;
    for(int i=0; i<m; i++) {
      int u, v, cost;
      cin >> u >> v >> cost;
      u--; v--;
      G[u].pb(edge(v, cost));
      G[v].pb(edge(u, cost));
    }
    int ans = dij(s, c, g);
    cout << ans << endl;
  }
}